Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I get TextBox in a GridView row when Edit button is clicked if the headers are not databound?
    primarykey
    data
    text
    <p>I have a <code>GridView</code>, and the header fields of the <code>GridView</code> are the items from a <code>ListBox</code> in my program. Therefore the number of columns generated is dynamic every time I run. Based on this, if I click the Edit button associated inside my <code>GridView</code>, how do I generate a <code>TextBox</code> for each cell of that row?</p> <p>The .cs code I have written is:</p> <pre><code>protected void DONE4_Click(object sender, EventArgs e) { Panel7.Visible = true; SqlDataAdapter mydat = new SqlDataAdapter("SELECT DISTINCT Profile_Instance FROM Profile_Master", con); DataSet dst = new DataSet(); mydat.Fill(dst, "Table"); ListBox3.Items.Clear(); ListBox3.DataSource = dst.Tables[0]; ListBox3.DataTextField = dst.Tables[0].Columns["Profile_Instance"].ColumnName; ListBox3.DataBind(); int count = ListBox3.Items.Count; DataTable dt = new DataTable(); DataRow rw = default(DataRow); for (int i = 0; i &lt; ListBox1.Items.Count; i++) { dt.Columns.Add(ListBox1.Items[i].ToString(), System.Type.GetType("System.String")); } for (int j = 0; j &lt; count; j++) { rw = dt.NewRow(); for (int i = 0; i &lt; ListBox1.Items.Count; i++) { rw[ListBox1.Items[i].ToString()] = " "; } dt.Rows.Add(rw); } GridView2.DataSource = dt; GridView2.DataBind(); foreach (GridViewRow grdRow in GridView2.Rows) { DropDownList bind_dropdownlist = new DropDownList(); // defining the property of the DropDownList as bind_dropdownlist bind_dropdownlist = (DropDownList)(GridView2.Rows[grdRow.RowIndex].Cells[0].FindControl("Pro_List")); // finding the DropDownList from the gridiew for binding SqlDataAdapter mydata = new SqlDataAdapter("SELECT DISTINCT Profile_Instance FROM Profile_Master", con); DataSet dset = new DataSet(); // binding the DropDownList with the dataset ds mydata.Fill(dset, "Table"); bind_dropdownlist.DataSource = dset; bind_dropdownlist.DataTextField = "Profile_Instance"; // set the DropDownList's DataTextField as designation which display the designation in the dropdownlist after fetching the data from database bind_dropdownlist.DataBind(); bind_dropdownlist.Items.Insert(0, new ListItem("---Choose Profile---", "-1")); } } </code></pre> <p>The design code for the <code>GridView</code> is:</p> <pre class="lang-xml prettyprint-override"><code>&lt;asp:Panel ID="Panel7" runat="server"&gt; &lt;asp:GridView ID="GridView2" runat="server" CellPadding="4" style="text-align: center; font-size: small" BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"&gt; &lt;Columns&gt; &lt;asp:TemplateField HeaderText=""&gt; &lt;ItemTemplate&gt; &lt;asp:DropDownList ID="Pro_List" runat="server"&gt; &lt;asp:ListItem&gt;--Select--&lt;/asp:ListItem&gt; &lt;/asp:DropDownList&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; &lt;asp:CommandField ShowEditButton="True" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; &lt;/asp:Panel&gt; </code></pre> <p>Can someone please help me on this? I hope the question is clear.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload