get input field value from Dynamically Created Table in ASP.Net C#

Viewed 58

I am creating dynamic table that get data from SQL table and displays in the table. Table is created successfully but now what i want is to get the value of input field that i have created in table td. I can get td value by this:

string sx = ds.Tables[0].Rows[1].ItemArray[1].ToString();

But can't access input field value on form submit. Help out!

SqlCommand cmd = new SqlCommand("  SELECT id,[Product_Name],tradePrice,scheme from [dbo].[Product_details]", connection);
da = new SqlDataAdapter(cmd);  
da.Fill(ds);
connection.Open();  
cmd.ExecuteNonQuery();
connection.Close();  
  
htmlTable.Append("<table style='width:100%'>");
htmlTable.Append("<tr style='background-color:#517c9d; color: white;'><th>Prod ID</th><th>Product Name</th><th>TP</th><th>Issue</th><th>Return</th><th>Scheme Rate</th><th>Total</th><th>Amount</th></tr>");  
  
if (!object.Equals(ds.Tables[0], null))  
{
    if (ds.Tables[0].Rows.Count > 0)  
    {  
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)  
        {  
            htmlTable.Append("<tr style='color: black;'>");  
            htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["id"] + "</td>");
            htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["Product_Name"] + "</td>");
            htmlTable.Append("<td id='tp'>" + ds.Tables[0].Rows[i]["tradePrice"] + "</td>");
            htmlTable.Append("<td><input class='form-control' type='text' name='' style='color:white; font-color:black' id=${txt_issue} runat='server'/></td>");
            htmlTable.Append("<td><input class='form-control' type='text' name='' style='color:white; font-color:black' id='txt_return' runat='server' /></td>");
            htmlTable.Append("<td id='scheme'>" + ds.Tables[0].Rows[i]["scheme"] + "</td>");
            htmlTable.Append("<td><input class='form-control' type='text' name='' style='color:white; font-color:black' id='txt_total' /></td>");
            htmlTable.Append("<td><input class='form-control' type='text' name='' style='color:white; font-color:black' id='txt_amount' /></td>");
            // htmlTable.Append("<td>" + ds.Tables[0].Rows[i]["ContactNo"] + "</td>");  
            htmlTable.Append("</tr>");
            string sx = ds.Tables[0].Rows[1].ItemArray[1].ToString();
            //string sdc = ds.Tables[0].Rows..Find("#txt_return").ToStrstring sx = ds.Tables[0].Rows[1].ItemArray.ToString();
                        
        }
        htmlTable.Append("</table>");  
        DBDataPlaceHolder.Controls.Add(new Literal { Text = htmlTable.ToString() });  
                    
    }  
    else  
    {
        htmlTable.Append("<tr>");  
        htmlTable.Append("<td align='center' colspan='4'>There is no Record.</td>");  
        htmlTable.Append("</tr>");  
    }
}
0 Answers
Related