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

  • Thread starter Thread starter meeraluv
  • Start date Start date
M

meeraluv

Guest
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;

Continue reading...
 
Back
Top