我有一个asp转发器,通过跟踪号码来绑定订单列表。我想知道在选中复选框时如何传递所选行的ID。我这样做只绑定选中的复选框。
<asp:Repeater ID="Repeater2" runat="server" OnItemDataBound="Repeater2_ItemDataBound">
<HeaderTemplate>
<table class=" table table-bordered">
<tr>
<th></th>
<th>Order Type</th>
<th>Job Name</th>
<th>Price</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="chkDisplayTitle" runat="server" /></td>
<td><%#Eval("Order") %></td>
<td><%#Eval("Job_Name") %></td>
<td><%#Eval("Price") %></td>
</tr>
</ItemTemplate>
<FooterTemplate>
<td></td>
<td></td>
<td>
<td>Subtotal:
<asp:Label ID="lblSubtotal" runat="server"></asp:Label>
</td>
</td>
</tr>
</table>
</FooterTemplate>
</asp:Repeater>
private void ConsolidateItems()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);
//======= Parameterized select Query.
string cmdText = "SELECT * FROM Order_TB WHERE Tracking_Number=@tracking AND Status=@status";
//====== Providning information to SQL command object about which query to
//====== execute and from where to get database connection information.
SqlCommand cmd = new SqlCommand(cmdText, con);
//===== Adding parameters/Values.
cmd.Parameters.AddWithValue("@tracking", hfid.Value);
cmd.Parameters.AddWithValue("@status", "Accepted");
if (con.State == ConnectionState.Closed)
{
con.Open();
}
Repeater2.DataSource = cmd.ExecuteReader();
Repeater2.DataBind();
con.Close();
}
答案 0 :(得分:0)
在ASPX上:
<asp:CheckBox ID="chkBoxID" runat="server" OnCommand="doSomething_Checked"
CommandArgument="<%# Some Binding Information%>" CommandName="NameForArgument"> </asp:CheckBox>
On Code-Behind:
protected void doSomething_Checked(object sender, CommandEventArgs e)
{
CheckBox ctrl = (CheckBox)sender;
RepeaterItem rpItem = ctrl.NamingContainer as RepeaterItem;
if (rpItem != null)
{
CheckBox chkBox = (CheckBox)rpItem.FindControl("chkBoxID");
chkBox.DoSomethingHere...
}
}
你可以这样做......