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

  • Home
  • SEARCH
  • 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 6710279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:00:12+00:00 2026-05-26T08:00:12+00:00

I am having editable Gridview with column named Country which has so long listing.

  • 0

I am having editable Gridview with column named Country which has so long listing.

When I am showing data the value of Country is in Label but when I choose edit should show DropDownList with country listings. I am able to show listings. it should show the country selected as that was in label.

I have tried with this but dropdownlist is filled with System.Row.DataRowView also it is not set at SelectedValue given as cvalue

aspx page

<asp:TemplateField HeaderText="Country">
                            <ItemTemplate>
                                <asp:Label ID="lblCountry" runat="server" Text='<%#Bind("Country")%>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList ID="ddlCCountry" runat="server" Height="21px" Style="margin-left: 0px"
                                    Width="194px">
                                    <asp:ListItem Value="-1">Select..</asp:ListItem>
                                    <asp:ListItem Value="af">Afghanistan</asp:ListItem>
                                    <asp:ListItem Value="ax">Aland Islands</asp:ListItem>
                                    <asp:ListItem Value="al">Albania</asp:ListItem>
                                 </asp:DropDownList>
                              <EditItemTemplate>  

.cs file

 void gvhoteldetail_RowDataBound(object sender, GridViewRowEventArgs e)
            {
                if (e.Row.RowState == DataControlRowState.Edit)
                {
                     string cnm="",cvalue="";
                     string getCountry = "Select * from tbl_countrynames where `Name`='" + cname + "'";
                     string getCountrynames = "Select * from tbl_countrynames";
                     MySqlConnection con = new MySqlConnection(connection);
                     MySqlCommand cmd1 = new MySqlCommand(getCountrynames, con);
                     DataSet ds1 = new DataSet();
                     MySqlDataAdapter da1 = new MySqlDataAdapter(cmd1);
                     da1.Fill(ds1);

                     MySqlCommand cmd = new MySqlCommand(getCountry, con);
                     DataSet ds = new DataSet();
                     MySqlDataAdapter da = new MySqlDataAdapter(cmd);
                     da.Fill(ds);
                     if (ds.Tables[0].Rows.Count > 0)
                     {
                            cnm = ds.Tables[0].Rows[0]["Name"].ToString();
                            cvalue = ds.Tables[0].Rows[0]["Value"].ToString();
                       }
                   DropDownList ddlcountry = (DropDownList)e.Row.FindControl("ddlCCountry");
                   ddlcountry.DataSource = ds1;
                   ddlcountry.SelectedValue = cvalue;
                   ddlcountry.DataBind();      
             }

What could be wrong?

  • 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-05-26T08:00:13+00:00Added an answer on May 26, 2026 at 8:00 am

    This worked for me. When populating the GridView, you should populate each DropDownList in the RowDataBound event:

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        numberFormatDA formatDA = new numberFormatDA();
    
        DataTable mytable = new DataTable();
        DataColumn formatIDcolumn = new DataColumn("fkNumberFormat");
        DataColumn formatNameColumn = new DataColumn("numberFormat");
    
        mytable.Columns.Add(formatIDcolumn);
        mytable.Columns.Add(formatNameColumn);
    
        DataSet ds = new DataSet();
        ds = formatDA.getNumberFormatsDS();
    
        if ((e.Row.RowState & DataControlRowState.Edit) > 0)
        {
            TextBox txtSite = (TextBox)e.Row.FindControl("txtIDSite");
    
            DropDownList ddl = (DropDownList)e.Row.FindControl("ddlNumberFormat");
            DataRow[] rows = ds.Tables[0].Select();
    
            foreach (DataRow row in rows)
            {
                DataRow newrow = mytable.NewRow();
                newrow["fkNumberFormat"] = row["idnumberFormat"];
                newrow["numberFormat"] = row["numberFormat"];
                mytable.Rows.Add(newrow);
            }
    
            ddl.DataSource = mytable;
            ddl.DataTextField = "numberFormat";
            ddl.DataValueField = "fkNumberFormat";
    
            int numberFormatID = 0;
            Label lblFormatID = (Label)e.Row.FindControl("numberFormatLabel");
            numberFormatID = Int32.Parse(lblFormatID.Text);
    
            ddl.SelectedValue = numberFormatID.ToString();
            ddl.DataBind();
        }
    }
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jqgrid 3.8. I have a grid which is having some editable
I am trying to make my UITableView Editable but I'm having some trouble with
I'm having a problem with data entry since switching to .NET 4.0. In my
I'm developing one AS3 application in which I need to add blank editable box
All right, after having worked through Cocoa Dev Central's Build a Core Data Application
I'm having an array of data in PHP. It is a lot of data
Yes, is it possible to have: A table having two column ( Should be
I have a GridView that allows editing the values in every column, in every
I'm having a bit of trouble with getting an editable block of text working
I am building one app having one list view showing list of users this

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.