Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8440393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:17:09+00:00 2026-06-10T08:17:09+00:00

I have a GridView , and the header fields of the GridView are the

  • 0

I have a GridView, and the header fields of the GridView are the items from a ListBox 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 GridView, how do I generate a TextBox for each cell of that row?

The .cs code I have written is:

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 < ListBox1.Items.Count; i++)
    {
        dt.Columns.Add(ListBox1.Items[i].ToString(),
                                       System.Type.GetType("System.String"));
    }

    for (int j = 0; j < count; j++)
    {
        rw = dt.NewRow();
        for (int i = 0; i < 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"));
    }
}

The design code for the GridView is:

<asp:Panel ID="Panel7" runat="server">
    <asp:GridView ID="GridView2" runat="server" CellPadding="4"
        style="text-align: center; font-size: small" BackColor="White" 
        BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px">

        <Columns>                
        <asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:DropDownList ID="Pro_List" runat="server">
                    <asp:ListItem>--Select--</asp:ListItem>                          
                </asp:DropDownList>
            </ItemTemplate>
        </asp:TemplateField>

        <asp:CommandField ShowEditButton="True" />

        </Columns>
    </asp:GridView>
</asp:Panel>

Can someone please help me on this? I hope the question is clear.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:17:11+00:00Added an answer on June 10, 2026 at 8:17 am

    If you are not Binding GridView and still want to access the controls within it, you can use the GridViewRow property.

    protected void grd_RowEditing(object sender, GridViewEditEventArgs e) 
    {
         GridViewRow selectRow = grd.Rows[e.NewEditIndex];
         TextBox txtKj=(TextBox)selectRow.Cells[3].FindControl("txtKjId"); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show the datatable header to gridview header. My datatable have dynamic
i am using asp.net gridview in header i have two columns column select all
I have a GridView populated from an ObjectDataSource with two items in its DataKeyNames
I have a gridview that i want to print its header on every page
I have gridview with 15 and above columns, I need to freeze the header
I have a gridview and sqldatasource. The default header text for each column is
I have a gridview and sqldatasource. I want to remove the header text underline
i have to fix the header in a gridview and i use this in
I have a GridView, with sortable headers. If I click on a header to
I have a gridview ...with multiple columns. If I click on one column, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.