locked
find id of checbox of obout gridview in code behind RRS feed

  • Question

  • User-1506965535 posted

    I want to find the id of obout gridview which is inside gridview in code behind. Here is my gridview

     <cc1:Grid ID="GrdConfirmation" EnableTypeValidation="true" runat="server" Width="100%"
            ShowFooter="false" AllowAddingRecords="true" AllowSorting="false" AutoGenerateColumns="false"
            FolderStyle="../Styles/Grid/style_12">
            <ClientSideEvents OnClientSelect="GrdConfirmation_OnClientSelect" />
            <Columns>
                <cc1:Column ID="Column1" DataField="MKEY" HeaderText="Select" ReadOnly="true" Width="5%"
                    runat="server">
                    <TemplateSettings TemplateId="gtchkConfirm" HeaderTemplateId="HTConfirm" />
                </cc1:Column>
                <cc1:Column ID="Sr_No" DataField="Sr_No" HeaderText="Sr No" Visible="true" Width="5%">
                    <TemplateSettings TemplateId="tplNumbering" />
                </cc1:Column>
                <cc1:Column ID="Line_Id" DataField="Line_Id" HeaderText="Line id" Visible="true"
                    Align="center" Width="5%">
                </cc1:Column>
                <cc1:Column ID="Item_Mkey" DataField="Item_Mkey" HeaderText="Item Mkey" Visible="true"
                    Align="center" Width="5%">
                </cc1:Column>
                <cc1:Column ID="Item_Code" DataField="Item_Code" HeaderText="Item Code" Visible="true"
                    Align="center" Width="5%">
                </cc1:Column>
                <cc1:Column ID="Item_Desc" DataField="Item_Desc" HeaderText="Item Description" Visible="true"
                    Align="center" Width="10%">
                </cc1:Column>
                <cc1:Column ID="Lot_Batch_No" DataField="Lot_Batch_No" HeaderText="Lot / Batch No."
                    Visible="true" Align="center" Width="5%">
                </cc1:Column>
                <cc1:Column ID="Exp_Dt" DataField="Exp_Dt" HeaderText="Exp Date" Visible="true" Align="center"
                    Width="5%">
                </cc1:Column>
                <cc1:Column ID="QTY1" DataField="Qty" HeaderText=" Quantity" Visible="true" Width="5%"
                    Align="center">
                </cc1:Column>
                <cc1:Column ID="Bx_Bg" DataField="Bx_Bg" HeaderText="Boxes/Bags" Visible="true" Width="5%"
                    Align="center">
                </cc1:Column>
                <cc1:Column ID="Net_Wgt" DataField="Net_Wgt" HeaderText="Net Weight" Visible="true"
                    Width="5%" Align="center">
                </cc1:Column>
                <cc1:Column ID="NO_OF_PALLETS" DataField="NO_OF_PALLETS" HeaderText="No Of Pallets"
                    Visible="true" Align="center" Width="5%">
                </cc1:Column>
                <cc1:Column ID="Default_Allot" DataField="Default_Allot" HeaderText="1Allocated Storage Bin No."
                    Visible="true" Width="10%" Align="right">
                </cc1:Column>
                <cc1:Column ID="Confirmed_Allot" DataField="Confirmed_Allot" HeaderText="Confirmed Storage Bin No."
                    Visible="true" Width="10%" Align="right">
                    <TemplateSettings TemplateId="TextBoxEditTemplate" />
                </cc1:Column>
                <cc1:Column ID="DAMAGED_QTY" DataField="DAMAGED_QTY" HeaderText="Damaged Qty in Units"
                    Visible="true" Width="5%" Align="right">
                </cc1:Column>
                <cc1:Column ID="SHORTFALL_QTY" DataField="SHORTFALL_QTY" HeaderText="Shortfall/ excess qty in units"
                    Visible="true" Width="5%" Align="right">
                </cc1:Column>
            </Columns>
            <AddEditDeleteSettings AddLinksPosition="Bottom" NewRecordPosition="Dynamic" />
            <Templates>
                <cc1:GridTemplate runat="server" ID="HTConfirm">
                    <Template>
                        <input type="checkbox" onclick="toggleSelection(this)" id="ChkSelector" />
                    </Template>
                </cc1:GridTemplate>
                <cc1:GridTemplate runat="server" ID="gtchkConfirm">
                    <Template>
                        <input type="checkbox" id="chk_grid_<%# Container.DataItem["Sr_No"] %>" onclick="copyrecord(this)" />
                    </Template>
                </cc1:GridTemplate>
            </Templates>
            <Templates>
                <cc1:GridTemplate runat="server" ID="TextBoxEditTemplate">
                    <Template>
                        <input type="text" name="TextBox1" id="Txtconfirm<%# (Container.RecordIndex) %>" 
                            class="excel-textbox" readonly="readonly" onfocus="GrdConfirmation.editWithTextBox(this)" />
                        <%--<asp:TextBox ID='Txtconfirm<%# (Container.RecordIndex) %>' CssClass="excel-textbox"
                            runat="server" Text="<%# Container.Value %>" ReadOnly="true" onfocus="GrdConfirmation.editWithTextBox(this)"></asp:TextBox>--%>
                    </Template>
                </cc1:GridTemplate>
                <cc1:GridTemplate runat="server" ID="tplNumbering">
                    <Template>
                        <b>
                            <%# (Container.RecordIndex + 1) %></b>
                    </Template>
                </cc1:GridTemplate>
                <cc1:GridTemplate ID="TemplateWithCheckbox">
                    <Template>
                        <asp:CheckBox runat="server" ID="ChkID" ToolTip="<%# Container.Value %>" />
                    </Template>
                </cc1:GridTemplate>
            </Templates>
        </cc1:Grid>

    I have bolded the checkbox

    Tuesday, October 13, 2015 6:26 AM

Answers

  • User603616845 posted

    Hi,

    You can get dynamic generated id like this..

    protected void gridviwe1_RowCreated(object sender, GridViewRowEventArgs e)
            {
    
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        for (int rowId = 0; rowId < 5; rowId++)
                        {
                            TextBox txtBox = new TextBox();
                            txtBox.ID = "_registration" + e.Row.RowIndex + "_" + rowId;
                            txtBox.Text = "_registration" + e.Row.RowIndex + "_" + rowId;
                            e.Row.Cells[7].Controls.Add(txtBox);
                        }
                    }
                } 

    or

    protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox chk = (CheckBox) gridRolApp.Rows.Cells[0].FindControl("chkRole"+id[0].Role_ShortName;
                if (chk != null && chk.Checked)
                {
                    // ...do your code
                }
            }
        }

    See this discussion, might it help you.

    http://www.c-sharpcorner.com/Forums/Thread/217846/-how-to-get-checked-value-of-dynamic-checkbox-inside-grid.aspx

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 13, 2015 6:44 AM
  • User603616845 posted

    Hi,

    Here gridRolApp was your gridview id.

    In your case, you might be use following... Try this, is it working..

     protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GrdConfirmation.Rows)
            {
                CheckBox chk = (CheckBox)GrdConfirmation.Rows.Cells[0].FindControl("chk_grid_"+GrdConfirmation.Rows.Cells["Sr_No"]);
                if (chk != null && chk.Checked)
                {
                    // ...do your code
                }
            }
        }

    I hope, it should work.

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 8:56 AM

All replies

  • User603616845 posted

    Hi,

    You can get dynamic generated id like this..

    protected void gridviwe1_RowCreated(object sender, GridViewRowEventArgs e)
            {
    
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        for (int rowId = 0; rowId < 5; rowId++)
                        {
                            TextBox txtBox = new TextBox();
                            txtBox.ID = "_registration" + e.Row.RowIndex + "_" + rowId;
                            txtBox.Text = "_registration" + e.Row.RowIndex + "_" + rowId;
                            e.Row.Cells[7].Controls.Add(txtBox);
                        }
                    }
                } 

    or

    protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox chk = (CheckBox) gridRolApp.Rows.Cells[0].FindControl("chkRole"+id[0].Role_ShortName;
                if (chk != null && chk.Checked)
                {
                    // ...do your code
                }
            }
        }

    See this discussion, might it help you.

    http://www.c-sharpcorner.com/Forums/Thread/217846/-how-to-get-checked-value-of-dynamic-checkbox-inside-grid.aspx

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 13, 2015 6:44 AM
  • User-1506965535 posted

    what are

    1. gridRolApp

    2. id[0] according to my gridview, can you edit and give as I am using 2nd method

    Tuesday, October 13, 2015 6:54 AM
  • User603616845 posted

    Hi,

    Here gridRolApp was your gridview id.

    In your case, you might be use following... Try this, is it working..

     protected void Button1_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GrdConfirmation.Rows)
            {
                CheckBox chk = (CheckBox)GrdConfirmation.Rows.Cells[0].FindControl("chk_grid_"+GrdConfirmation.Rows.Cells["Sr_No"]);
                if (chk != null && chk.Checked)
                {
                    // ...do your code
                }
            }
        }

    I hope, it should work.

    thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 8:56 AM