I have wird problem with gridview and select checkbox for one row.
I get correct Text in Label, but if i select checkbox from first row:
I get: Room not pick
BUTTON CLICK
protected void bookButton_Click(object sender, EventArgs e) {
foreach (GridViewRow row in GridView1.Rows)
{
var chk = (HtmlInputCheckBox) row.FindControl("checkboxID");
int id_room = Convert.ToInt32(row.Cells[4].Text);
if (chk.Checked)
{
Label1.Text = id_room.ToString();
/*
String CS = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(CS))
{
//STORED PROCEDURE CALL
}
}
else
{
Label1.Text ="Room not pick";
}
*/
}
}
AND GRIDVIEW
<asp:GridView ID="GridView1" runat="server" CssClass="table border-0 table-hover" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" GridLines="None" BorderWidth="0px">
<Columns>
<asp:BoundField DataField="Number" HeaderText="Number" SortExpression="Number" />
<asp:BoundField DataField="Picture" HeaderText="Picture" SortExpression="Picture" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="ID" HeaderText="IDP" SortExpression="ID" />
<asp:TemplateField>
<ItemTemplate>
<input type="checkbox" CssClass="custom-checkbox" ID="checkboxID" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Aucun commentaire:
Enregistrer un commentaire