The gridview and checkbox are used in combination to implement multiple selections and display them with tables.

Source: Internet
Author: User

It is mainly used to select with checkbox,

After displayed in the gridview, I select several checkboxes and click Apply to display the following interface in the background,

I clicked two on the top, and then I used table to display two records.

1. First, add a check box in the gridview.

Add check box code

<Columns>
<asp:TemplateField >
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="CheckBoxALL" runat="server" AutoPostBack="True" oncheckedchanged="HeaderCheckBoxALL_CheckedChanged" />
</HeaderTemplate>
<HeaderStyle Font-Size="9pt" Width="20px" />
</asp:TemplateField>

Double-click the button applied.

Protected void btsq_click (Object sender, eventargs E)
{

// Check box selected for storing with ilist.
Ilist <string> zcbmlist = new list <string> ();
For (INT I = 0; I <= gridview1.rows. Count-1; I ++)
{
Checkbox cbox = (checkbox) (gridview1.rows [I]. findcontrol ("checkbox1 "));
If (cbox. Checked = true)
{
// Check which check box is selected cyclically and save the value of the second column of the row to ilist. The second column here is the unique label column.
Zcbmlist. Add (gridview1.rows [I]. cells [2]. Text );


}

}

// Use session to pass the value.
Session ["zcbmlist"] = zcbmlist;
Response. Redirect ("shenqing. aspx ");
Return;
}

After the event is selected, go to the shenqing. aspx interface to accept the session.

Public partial class shenqing: modulepage
{
Ilist <string> zcbmlist = NULL;
Protected void page_load (Object sender, eventargs E)
{
// Accept the session value passed in the previous interface
Zcbmlist = session ["zcbmlist"] As list <string>;
If (! Ispostback)
{
String sql1 = "select asset code, device code, device name, specification and model, self-number, production date, manufacturer, asset original value, book value, remarks, usage from basic device data table where ";
// Use the foreach statement and splicing function to traverse the transmitted values of the check box.
Foreach (VAR zcbm in zcbmlist)
{
If (zcbmlist. indexof (zcbm) <zcbmlist. Count-1)
{
Sql1 + = "asset code = '" + zcbm + "' or ";
}
Else
{
Sql1 + = "asset code = '" + zcbm + "'";
}

}

Datatable table = oraclehelper. executedataset (base. Conn, commandtype. Text, sql1). Tables [0];
// Store the table. Otherwise, the table will be blank after you do not refresh the page, and an error will occur. BIND at the front-end.
Viewstate ["table"] = table;

}
}

The background is basically as shown above. Next we will traverse the foreground. Traverse <tr>. <Asp: textbox> change to <input type = "text">

<% Foreach (system. Data. datarow row in (system. Data. datatable) viewstate ["table"]). Rows)
{%>
<Tr>
<TD class = "style65">
<Input type = "text" id = "tbzcbm" class = "smallinput" readonly = "true" width = "118px" value = "<% = row [" asset code "] %> "/>
</TD>
<TD class = "style13">
<Input type = "text" id = "tbzcmc" class = "smallinput" readonly = "true" value = "<% = row [" device name "] %>"> </input>
</TD>
<TD class = "style41">
<Input type = "text" id = "tbzcxh" class = "smallinput" readonly = "true" value = "<% = row [" "] %>"> </input>
</TD>
<TD class = "style42">
<Input type = "text" id = "tbzbh" class = "smallinput" readonly = "true" value = "<% = row [" self-numbered "] %>"> </input>
</TD>
<TD class = "style16">
<Input type = "text" id = "tbtcrq" class = "smallinput" readonly = "true" value = "<% = row [" production date "] %>"> </input>
</TD>
<TD class = "style43">
<Input type = "text" id = "tbsccj" class = "smallinput" readonly = "true" value = "<% = row [" "] %>"> </input>
</TD>
<TD class = "style44">
<Input type = "text" id = "tbyz" class = "smallinput" readonly = "true" value = "<% = row [" asset Original Value "] %>"> </input>
</TD>
<TD class = "style19">
<Input type = "text" id = "tbzmjz" class = "smallinput" readonly = "true" value = "<% = row [" book value "] %>"> </input>
</TD>
<TD class = "style74">
<Input type = "text" id = "tbbz" class = "smallinput" readonly = "true" value = "<% = row [" Remarks "] %>"> </ input>
</TD>
</Tr>
<% }%>

In this way, you do not need to use a table in the gridview to dynamically generate a form.

If you do not understand it, you can add 9984296.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.