页面上:
<asp:datagrid id="DataGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="False" Width="100%"
DataKeyField="bh" PageSize="10" BorderWidth="1px" BorderColor="#9BA6DB">
<AlternatingItemStyle CssClass="zy_tr"></AlternatingItemStyle>
<ItemStyle CssClass="zy_item"></ItemStyle>
<HeaderStyle CssClass="zy_title"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="wdlb" HeaderText="序号"></asp:BoundColumn>
<asp:TemplateColumn>
<HeaderTemplate>
序号
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataSetIndex + 1 %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="文档名称">
<ItemTemplate>
<asp:HyperLink id="HyperLink1" runat="server">
<%# DataBinder.Eval(Container.DataItem,"wdmc")%>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ytfl" HeaderText="用途分类"></asp:BoundColumn>
<asp:BoundColumn DataField="bx_mc" HeaderText="必须"></asp:BoundColumn>
<asp:BoundColumn DataField="zt_mc" HeaderText="状态"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="操作">
<ItemTemplate>
<asp:CheckBox id="record" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Visible="False"></PagerStyle>
</asp:datagrid>
DataKeyField="bh" PageSize="10" BorderWidth="1px" BorderColor="#9BA6DB">
<AlternatingItemStyle CssClass="zy_tr"></AlternatingItemStyle>
<ItemStyle CssClass="zy_item"></ItemStyle>
<HeaderStyle CssClass="zy_title"></HeaderStyle>
<Columns>
<asp:BoundColumn Visible="False" DataField="wdlb" HeaderText="序号"></asp:BoundColumn>
<asp:TemplateColumn>
<HeaderTemplate>
序号
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataSetIndex + 1 %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="文档名称">
<ItemTemplate>
<asp:HyperLink id="HyperLink1" runat="server">
<%# DataBinder.Eval(Container.DataItem,"wdmc")%>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ytfl" HeaderText="用途分类"></asp:BoundColumn>
<asp:BoundColumn DataField="bx_mc" HeaderText="必须"></asp:BoundColumn>
<asp:BoundColumn DataField="zt_mc" HeaderText="状态"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="操作">
<ItemTemplate>
<asp:CheckBox id="record" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Visible="False"></PagerStyle>
</asp:datagrid>
后台:
1 private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
2 {
3
4 if(e.Item.ItemType!=ListItemType.Header&&e.Item.ItemIndex>=0)
5 {
6 if(e.Item.Cells[0].Text=="1")
7 {
8 ((CheckBox)e.Item.Cells[0].FindControl("record")).Visible=true;
9 }
10 else
11 {
12 ((CheckBox)e.Item.Cells[0].FindControl("record")).Visible=false;
13 }
14 try
15 {
16 HyperLink link1=((HyperLink)e.Item.FindControl("HyperLink1"));
17 link1.NavigateUrl="add.aspx?bh="+DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
18 }
19 catch(Exception e1)
20 {
21 Response.Write(e1.Message.ToString());
22 }
23
24
25 }
26 }
2 {
3
4 if(e.Item.ItemType!=ListItemType.Header&&e.Item.ItemIndex>=0)
5 {
6 if(e.Item.Cells[0].Text=="1")
7 {
8 ((CheckBox)e.Item.Cells[0].FindControl("record")).Visible=true;
9 }
10 else
11 {
12 ((CheckBox)e.Item.Cells[0].FindControl("record")).Visible=false;
13 }
14 try
15 {
16 HyperLink link1=((HyperLink)e.Item.FindControl("HyperLink1"));
17 link1.NavigateUrl="add.aspx?bh="+DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
18 }
19 catch(Exception e1)
20 {
21 Response.Write(e1.Message.ToString());
22 }
23
24
25 }
26 }