DataGrid里实现简单的行合并效果
DataGrid行合并。
在DataGrid里的ItemCreated事件时,重定向Render流
1private void grdSearchResults_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
2 {
3 try
4 {
5 ListItemType itemtype = e.Item.ItemType;
6 if(itemtype == ListItemType.Item || itemtype == ListItemType.AlternatingItem)
7 {
8 BindSerialNum(e);
9 //把主健值保存下来,为绑投标值用。
10 ViewState["PK_Cert_Info_ID"] = grdSearchResults.DataKeys[e.Item.ItemIndex].ToString();
11 //投标值和分值特殊处理
12 e.Item.SetRenderMethodDelegate(new RenderMethod(NewRenderMethod));
13 }
14 }
15 catch(Exception ex)
16 {
17 Response.Write("<script>alert('"+ex.ToString()+"')</script>");
18 }
19 }
1private void grdSearchResults_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
2 {
3 try
4 {
5 ListItemType itemtype = e.Item.ItemType;
6 if(itemtype == ListItemType.Item || itemtype == ListItemType.AlternatingItem)
7 {
8 BindSerialNum(e);
9 //把主健值保存下来,为绑投标值用。
10 ViewState["PK_Cert_Info_ID"] = grdSearchResults.DataKeys[e.Item.ItemIndex].ToString();
11 //投标值和分值特殊处理
12 e.Item.SetRenderMethodDelegate(new RenderMethod(NewRenderMethod));
13 }
14 }
15 catch(Exception ex)
16 {
17 Response.Write("<script>alert('"+ex.ToString()+"')</script>");
18 }
19 }
在自定义Render方法里实现效果
1 private void NewRenderMethod(HtmlTextWriter writer, Control ctl)
2 {
3 //把前面的控件输出
4 for(int i = 0 ;i <= 5; i ++)
5 {
6 TableCell cell = (TableCell)ctl.Controls[i];
7 cell.RowSpan = 2;
8 cell.RenderControl(writer);
9 }
10 //得到特定资质下的所有投标值
11 string PK_Cert_Info_ID = ViewState["PK_Cert_Info_ID"].ToString();
12 DataTable dt = ProjectCert_BLL.SelectBidValuesByCertID(PK_Cert_Info_ID);
13
14 //特别的输出投标值
15 TableCell tablecell = (TableCell)ctl.Controls[6];
16 if(tablecell != null)
17 {
18 //遍历投标值
19 foreach(DataRow row in dt.Rows)
20 {
21 //给DataGrid的投标值列手工绑定数据
22 Label lb = new Label();
23 lb.Text = row["BidValue_Name"].ToString();
24 tablecell.Controls.Add(lb);
25 //换行
26 LiteralControl lctr = new LiteralControl("<BR>");
27 tablecell.Controls.Add(lctr);
28 }
29 //输出到HtmlTextWriter流中
30 tablecell.RenderControl(writer);
31 }
32 //特别的输出投标值的分值
33 TableCell tablecell2 = (TableCell)ctl.Controls[7];
34 if(tablecell2 != null)
35 {
36
37 for(int i=0;i<dt.Rows.Count;i++)
38 {
39 TextBox txtBidValue = new TextBox();
40 txtBidValue.CssClass = "TextBox";
41 txtBidValue.ID = txtBidValue+i.ToString();
42 tablecell2.Controls.Add(txtBidValue);
43 //换行
44 LiteralControl lctr = new LiteralControl("<BR>");
45 tablecell2.Controls.Add(lctr);
46 }
47 //输出到HtmlTextWriter流中
48 tablecell2.RenderControl(writer);
49 }
50 }
1 private void NewRenderMethod(HtmlTextWriter writer, Control ctl)
2 {
3 //把前面的控件输出
4 for(int i = 0 ;i <= 5; i ++)
5 {
6 TableCell cell = (TableCell)ctl.Controls[i];
7 cell.RowSpan = 2;
8 cell.RenderControl(writer);
9 }
10 //得到特定资质下的所有投标值
11 string PK_Cert_Info_ID = ViewState["PK_Cert_Info_ID"].ToString();
12 DataTable dt = ProjectCert_BLL.SelectBidValuesByCertID(PK_Cert_Info_ID);
13
14 //特别的输出投标值
15 TableCell tablecell = (TableCell)ctl.Controls[6];
16 if(tablecell != null)
17 {
18 //遍历投标值
19 foreach(DataRow row in dt.Rows)
20 {
21 //给DataGrid的投标值列手工绑定数据
22 Label lb = new Label();
23 lb.Text = row["BidValue_Name"].ToString();
24 tablecell.Controls.Add(lb);
25 //换行
26 LiteralControl lctr = new LiteralControl("<BR>");
27 tablecell.Controls.Add(lctr);
28 }
29 //输出到HtmlTextWriter流中
30 tablecell.RenderControl(writer);
31 }
32 //特别的输出投标值的分值
33 TableCell tablecell2 = (TableCell)ctl.Controls[7];
34 if(tablecell2 != null)
35 {
36
37 for(int i=0;i<dt.Rows.Count;i++)
38 {
39 TextBox txtBidValue = new TextBox();
40 txtBidValue.CssClass = "TextBox";
41 txtBidValue.ID = txtBidValue+i.ToString();
42 tablecell2.Controls.Add(txtBidValue);
43 //换行
44 LiteralControl lctr = new LiteralControl("<BR>");
45 tablecell2.Controls.Add(lctr);
46 }
47 //输出到HtmlTextWriter流中
48 tablecell2.RenderControl(writer);
49 }
50 }