调拨代码汇总

 一、合并单元格

 

private DataTable CreateDataTable()
        {
            DataTable dt 
= new DataTable();
            dt.Columns.Add(
"Year");
            dt.Columns.Add(
"Term");
            dt.Columns.Add(
"Course");
            dt.Columns.Add(
"Teacher");
            dt.Columns.Add(
"Score");
            dt.Columns.Add(
"Remark");

            dt.Rows.Add(
"2010年""第一学期""语文""张三""75""及格");
            dt.Rows.Add(
"2010年""第一学期""数学""李四""85""良好");
            dt.Rows.Add(
"2010年""第二学期""语文""李四""75""及格");
            dt.Rows.Add(
"2010年""第二学期""数学""李四""95""优秀");
            dt.Rows.Add(
"2010年""第二学期""政治""李四""57""不及格");

            
return dt;
        }

        
private void BindGrid()
        {
            grdScore.DataSource 
= CreateDataTable();
            grdScore.DataBind();
            GroupGridView(grdScore, 
new int[] { 013 });
        }

        
private void GroupGridView(GridView gv, int[] rowCounts)
        {
            
string strContent;
            
int i;
            
int count;
            
int rowSpanCount;

            
foreach (int rowCount in rowCounts)
            {
                strContent 
= string.Empty;
                i 
= 0;
                count 
= 0;
                rowSpanCount 
= 2;

                
foreach (GridViewRow row in gv.Rows)
                {

                    
if (strContent == row.Cells[rowCount].Text)
                    {
                        gv.Rows[count 
- 1].Cells[rowCount].RowSpan = rowSpanCount++;
                        gv.Rows[i].Cells[rowCount].Visible 
= false;
                    }
                    
else
                    {
                        rowSpanCount 
= 2;
                        count 
= i + 1;
                    }
                    strContent 
= row.Cells[rowCount].Text;

                    i
++;
                }
            }
        }

 

 

二、页面打印

 

window.print(); //简单又好用

 

三、Gridview中链接直接弹出页面

 

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            BackColor
="White" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px" 
            CellPadding
="4" Width="616px">
            
<RowStyle BackColor="White" ForeColor="#003399" />
            
<Columns>
                
<asp:TemplateField HeaderText="编号">
                    
<ItemTemplate>
                      
<asp:HyperLink ID="HyperLink1" onclick="javascript: window.open('Default.aspx?Id='+this.innerText+'')" style="text-decoration: underline;cursor:hand" runat="server"><%Eval("Code"%></asp:HyperLink>
                      
<%--  <asp:HyperLink ID="HyperLink1" onclick="bindData(this.innerText)" style="text-decoration: underline;cursor:hand" runat="server"><%# Eval("Code"%></asp:HyperLink>--%>
<%--                         <a onclick="bindData(this.innerText)" style="text-decoration: underline;cursor:hand"><%# Eval("Code"%></a>--%>
                    
</ItemTemplate>
                
</asp:TemplateField>
                
<asp:BoundField DataField="Name" HeaderText="名称" />
                
<asp:BoundField DataField="Store" HeaderText="所属仓库" />
                
<asp:BoundField DataField="StoreInfo" HeaderText="仓管信息" />
                
<asp:BoundField DataField="Number" HeaderText="商品数" />
            
</Columns>
            
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            
<PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
            
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            
<HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
        
</asp:GridView>

 下面的代码是在上边的基础上添加了对IE的控制的

  <asp:HyperLink ID="HyperLink1" onclick="javascript: window.open('Default.aspx?Id='+this.innerText+'','查看','top=150,left=50,toolbar=no, menubar=no,scrollbars=yes, resizable=no, location=no, status=no, width=850,height=400');" style="text-decoration: underline;cursor:hand" runat="server"><%Eval("Code"%></asp:HyperLink>

 

posted @ 2011-06-25 17:16  Kevin.Cheung  阅读(285)  评论(0编辑  收藏  举报