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 9246081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:24:39+00:00 2026-06-18T09:24:39+00:00

i have a gridview on the form and have some template field, one of

  • 0

i have a gridview on the form and have some template field, one of them is:

<asp:TemplateField HeaderText="Country" HeaderStyle-HorizontalAlign="Left">
    <EditItemTemplate>
        <asp:DropDownList ID="DdlCountry" runat="server" DataTextField="Country" DataValueField="Sno">
        </asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateField>

now on the RowEditing event i need to get the selected value of dropdownlist of country and then i will set that value as Ddlcountry.selectedvalue=value; so that when dropdownlist of edit item template appears it will show the selected value not the 0 index of dropdownlist. but i am unable to get the value of dropdown list.
i have tried this already:

int index = e.NewEditIndex;
DropDownList DdlCountry = GridView1.Rows[index].FindControl("DdlCountry") as DropDownList;

need help please.
thanx.

  • 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-18T09:24:41+00:00Added an answer on June 18, 2026 at 9:24 am

    You need to databind the GridView again to be able to access the control in the EditItemTemplate. So try this:

    int index = e.NewEditIndex;
    DataBindGridView();  // this is a method which assigns the DataSource and calls GridView1.DataBind()
    DropDownList DdlCountry = GridView1.Rows[index].FindControl("DdlCountry") as DropDownList;
    

    But instead i would use RowDataBound for this, otherwise you’re duplicating code:

    protected void gridView1_RowDataBound(object sender, GridViewEditEventArgs e)
    {
     if (e.Row.RowType == DataControlRowType.DataRow)
      {
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
              DropDownList DdlCountry = (DropDownList)e.Row.FindControl("DdlCountry");
              // bind DropDown manually
              DdlCountry.DataSource = GetCountryDataSource();
              DdlCountry.DataTextField = "country_name";
              DdlCountry.DataValueField = "country_id";
              DdlCountry.DataBind();
    
              DataRowView dr = e.Row.DataItem as DataRowView;
              Ddlcountry.SelectedValue = value; // you can use e.Row.DataItem to get the value
            }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASP.NET VB, I have a form with some text boxes and a Gridview.
We have a command button on an ASP.Net web form with a GridView that
I have a DevExpress GridView in my form and I need to change some
I have a asp.net page with some user controls in it. One of the
I have form that have some fields with requireFieldValidation and also Gridview with edit
I have a gridview that is bound to a datasource on a Windows Form
I have a GridView bound to an DataSource query with parameters tied to form
I have a GridView, radGvA133s, on my main form, MainForm. I would like to
I have got 2 DropDownList s on my Form and 1 GridView . I
I have web form with a GridView and a few controls in the GridView.

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.