Как я могу выбрать данные из gridview с помощью флажка и таблицы обновления..
Я использовал различные типы код для выбора данных из таблицы с помощью chechkbox, чтобы обновить некоторые данные в GridView с помощью кода C#.
Что я уже пробовал:
мой код gridview.
<div class="widget-content"> <asp:GridView ID="GridNewPins" AutoGenerateColumns="false" GridLines="None" runat="server" CssClass="table table-striped table-bordered"> <Columns> <asp:TemplateField ItemStyle-Width="40px"> <HeaderTemplate> <asp:CheckBox ID="chkboxSelectAll" runat="server" onclick="CheckAllEmp(this);" /> </HeaderTemplate> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" /> <ItemTemplate> <asp:CheckBox ID="chkSelect" runat="server" /> <!-- <asp:HiddenField ID="hdpinslno" runat="server" Value='<%# Eval("Pinslno") %>' /> this is not working and i don't understand how can i use this code. --> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="PinSlNo" HeaderText="PinSlNo" /> <asp:BoundField DataField="PlanName" HeaderText="PlanName" /> <asp:BoundField DataField="Pin" HeaderText="Pin" /> <asp:BoundField DataField="PinId" HeaderText="PinId" /> <asp:BoundField DataField="Status" HeaderText="Status" /> <asp:BoundField DataField="GenerateDate" HeaderText="GenerateDate" /> <asp:BoundField DataField="PinValue" HeaderText="PinValue" /> </Columns> </asp:GridView> </div> <!-- /widget-content --> <div class="form-actions"> <asp:Button runat="server" ID="btnActive" class="btn btn-success" Text="DeActive" OnClick="btnActive_Click" /></div> </div>
мой код на c#..
protected void btnActive_Click(object sender, EventArgs e) { string msg = "Reg no. of "; try { foreach (GridViewRow row in this.GridNewPins.Rows) { CheckBox chkSelect = (CheckBox)row.FindControl("chkSelect"); if (chkSelect != null && chkSelect.Checked) { // string obj = ((HiddenField)this.GridNewPins.Rows[row.RowIndex].FindControl("hdpinslno")).Value.ToString().Trim(); // I have tried this code but it's working. string obj = ; // how can call selected line here for update data DbCommand cmd = DataAccess.CreateCommandText(); cmd.CommandText="update MemberVsPinTransfer set CancelPin = 1 where PinSlNo = @pinno"; cmd.Parameters.Add(DataAccess.CreateParameter(cmd, "pinno", DbType.String, obj)); int i = DataAccess.ExecuteNonQuery(cmd); if (i > 0) { msg += obj + ", "; } } } msg += "Deactivated is successful"; } catch { msg = "there is something problem try again"; bindnewpins(); } bindnewpins(); Message.Show(msg); }