Dynamic Textboxes with ID as the key id from databa -ASP.net ,C# RRS feed

  • Question

  • I have a Gridview inside a Repeater control.
     <asp:Repeater ID="rptdept" runat="server" OnItemDataBound="rptdept_ItemDataBound">
        <div class="panel panel-default">
      <div class="panel-heading"><%# Eval("DEPT_DESCRIPTION") %></div>
    <asp:HiddenField ID="hfdeptid" runat="server" Value='<%# Eval("DEPT_ID") %>' />
            <asp:GridView CssClass="table table-hover" runat="server" ID="gdvstrheader"
            AutoGenerateColumns="false" ShowHeader="False" >
    <asp:Label ID="lbldescription" runat="server" Text='<%# Eval("SH_DESCRIPTION")%>'/>
        <asp:TextBox ID='sh_txtbox' runat="server"  class="form-control" ></asp:TextBox>
    </div>          </ItemTemplate>  

     protected void rptdept_ItemDataBound(object sender, RepeaterItemEventArgs e)
                Session["rptrdeptId"] = null;
                string deptId = (e.Item.FindControl("hfdeptid") as HiddenField).Value;
                Session["rptrdeptId"] = deptId;
                GridView gdvstrheader = e.Item.FindControl("gdvstrheader") as GridView;
                gdvstrheader.RowDataBound += new GridViewRowEventHandler(gdvstrheader_RowDataBound);
                gdvstrheader.DataSource = GetData("SELECT  distinct SH_ID,SH_DESCRIPTION FROM STORE_HEADER WHERE dept_id='" + Session["rptrdeptId"] + "'");

            private void gdvstrheader_RowDataBound(object sender, GridViewRowEventArgs e)
                //Checking the RowType of the Row  
                if (e.Row.RowType == DataControlRowType.DataRow)
                    string deptId = Convert.ToString(Session["dpt_id"]);
                    string userdept = GetUserDepartment(string.Format("SELECT  u_name FROM user_auth WHERE dept_id='{0}'", deptId));
                    String uname = Session["u_name"].ToString();
                    if (Convert.ToString(Session["dpt_id"]) == userdept)
                        DataTable dt = new DataTable();
                        dt = GetData(string.Format("select SH_ID,SH_DESCRIPTION from STORE_HEADER WHERE ACTIVE='Y' and dept_id='{0}' order by desc", deptId));
                        Label lbldescription = e.Row.FindControl("lbldescription") as Label;
                        DataRow[] founddesc = dt.Select("SH_DESCRIPTION = '" + lbldescription.Text + "'");
                                   if (founddesc.Length != 0)
                             TextBox txtbox1 = e.Row.FindControl("txtbox1") as TextBox;
                            txtbox1.Enabled = true;
                        }    } }
    in this..my problem how i will make this Textbox Id to SH_ID which is retirving from the table.i need to make the textbox id a unique ID as SH_ID
     TextBox txtbox1 = e.Row.FindControl("txtbox1") as TextBox;
                            txtbox1.Enabled = true;
    Monday, September 7, 2020 6:47 AM

All replies

  • Hi meeraluv,

    Thank you for posting here.

    According to your description, your issue is more related to ASP.NET. Therefore, it will be more appropriate to ask your question in ASP.NET forum.

    Thank you for your understanding.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 8, 2020 1:27 AM