private string cai = null;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int i=0;
CheckBox cb = new CheckBox();
for (i = 0; i < GridView1.Rows.Count; i++)
{
cb = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if (cb.Checked == true)
{
cai += cb.Text;
}
}
Response.Write(cai);
}
aspx代码
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ShoppingDBConnectionString %>"
SelectCommand="SELECT [Cname], [Cimage] FROM [Tcai]"></asp:SqlDataSource>
<center>
</center>
<center>
</center>
<center>
</center>
<center>
</center>
<center>
</center>
<center>
</center>
<center>
</center>
<center>
</center>
<center>
<table width="800px">
<tr>
<td style="width: 107px">
</td>
<td style="width: 400px" >
</td>
<td >
</td>
</tr>
<tr>
<td style=" width: 107px;">
</td>
<td style="width: 400px;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" ShowHeader="False" Width="350px">
<Columns>
<asp:TemplateField HeaderText="Cname" SortExpression="Cname">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Cname") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Text='<%# Eval("Cname") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cimage" SortExpression="Cimage">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Cimage") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<img src="<%# Eval("Cimage") %>" alt="" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
<td style="width: 100px; height: 200px;">
</td>
</tr>
<tr>
<td style="width: 107px">
</td>
<td style="width: 400px">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></td>
<td style="width: 100px">
</td>
</tr>
</table>
</center>
</div>
</form> |