locked
Dynamic Textboxes with ID as the key id from database-ASp.net C# RRS feed

  • Question

  • I have a Gridview inside a Repeater control.

     <asp:Repeater ID="rptdept" runat="server" OnItemDataBound="rptdept_ItemDataBound">
              <ItemTemplate>
        <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" >
    <Columns>
    <asp:TemplateField>
    <ItemTemplate>
    <asp:Label ID="lbldescription" runat="server" Text='<%# Eval("SH_DESCRIPTION")%>'/>
    </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField>
    <ItemTemplate>        
        <asp:TextBox ID='sh_txtbox' runat="server"  class="form-control" ></asp:TextBox> 
           </ItemTemplate>
        </asp:TemplateField>
                    </Columns>
            </asp:GridView>        
    </div>          </ItemTemplate>  
          </asp:Repeater>
    
     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"] + "'");
                gdvstrheader.DataBind();
    
            }
    
    
            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:48 AM

All replies

  • Hello,

    For ASP.NET questions use the following forums https://forums.asp.net/


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, September 7, 2020 12:40 PM