Click here to Skip to main content
15,904,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Place holder. In that Text boxes are Dynamically generated. I have to put the Value of the Text Boxes in a GridView Column and update that in database.How will i bind the textboxes dynamically generated to a grid view
Posted
Comments
What have you tried and where is the problem?

1 solution

try this:

C#
<asp:textbox id="txtName" enabled="false" runat="server" >Text='<%# Eval("YourFieldName") %>'></asp:textbox>
 
Share this answer
 
v2
Comments
Member 10578683 14-Feb-14 3:58am    
int quantity = Convert.ToInt32(txtQuantity.Text.Trim());
// string serials = txtSerials.Text;
string status = "Under Repair";
//string qryCheck = "Select GatePassNo from Product_Details ";
//string[] serialArray = serials.Split(';');
if (txtQuantity.Text != "")
{
try
{
for (int i = 0; i < quantity; i++)
{

string tb1Val = string.Empty;
TextBox txtBox1 = (TextBox)PlaceHolder1.FindControl("tb1");
tb1Val = txtBox1.Text.Trim();
con.Open();

string qryInsertProduct = "insert into Product_Details(GatePassNo,ClientID,Product_name,SerialNo,Status,CheckIN_Date ,Customer_Name, Customer_location) values('" + GatePassNo + "','" + clientID + "','" + productName + "','" + tb1Val + "','" + status + "','" + entryDate + "','" + ddlCName.SelectedItem.Value + "','" + ddlCLocation.SelectedItem.Value + "')";
SqlCommand comInsertProduct = new SqlCommand(qryInsertProduct, con);
comInsertProduct.ExecuteNonQuery();
con.Close();
gdvProducts.Visible = true;
PopulateGridView();

}
}

catch (Exception ex)
{

}

finally
{
if (con.State == ConnectionState.Open)
{
con.Close();

}

<asp:GridView ID="gdvProducts" runat="server" AutoGenerateColumns="false" OnRowCancelingEdit="gdvProducts_RowCancelingEdit"
OnRowEditing="gdvProducts_RowEditing" OnRowUpdating="gdvProducts_RowUpdating"
OnRowDataBound="gdvProducts_RowDataBound"
önrowdeleting="gdvProducts_RowDeleting">
<columns>
<asp:TemplateField HeaderText="ID" ItemStyle-Width="10%" HeaderStyle-Font-Size="11px">
<itemtemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'>


<asp:TemplateField HeaderText="Product Name" ItemStyle-Width="20%" HeaderStyle-Font-Size="11px">
<itemtemplate>
<asp:Label ID="lblProduct" runat="server" Text='<%# Bind("Product_Name")%>'>

<edititemtemplate>
<asp:TextBox ID="txt_Edit_Product" runat="server" Text='<%# Bind("Product_Name") %>'>


<asp:TemplateField HeaderText="Serial Number" ItemStyle-Width="20%" HeaderStyle-Font-Size="11px">
<itemtemplate>
<asp:Label ID="lblSerial" runat="server" Text='<%# Bind("SerialNo")%>'>

<edititemtemplate>
<%--<asp:PlaceHolder ID="PlaceHolder1" runat="server">--%>
<asp:TextBox ID="tb1" enabled="false" runat="server" xmlns:asp="#unknown" Text='<%# Eval("SerialNo") %>'>
<%----%>


<asp:TemplateField HeaderText="Action" ControlStyle-ForeColor="Black" ItemStyle-Width="20%"
HeaderStyle-Font-Size="11px">
<itemtemplate>

<asp:ImageButton CssClass="txtBt
Member 10578683 14-Feb-14 4:00am    
This my code please check it and tell where is the problem
OPees 14-Feb-14 4:14am    
means which field you are not able to bind?
Member 10578683 14-Feb-14 5:05am    
SerialNo field. actually i have to bind the values that we enter in the randomly generated textboxes
OPees 14-Feb-14 5:25am    
sorry I m not getting you? is your SerialNo field is coming from DB?
if Yes have you tried '<%# Eval("SerialNo") %>'>?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900