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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:30:03+00:00 2026-05-22T01:30:03+00:00

In my application, when I edit a row in the gridview I choose some

  • 0

In my application, when I edit a row in the gridview I choose some new data from a dropdownlist.

I am populating the dropdown like this:

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
                DropDownList emailsListDL = (DropDownList)e.Row.FindControl("emailsDL");
                emailsListDL.DataSource = allUsersEmails;//list of strings with the emails of the users
                emailsListDL.DataBind();
            }
        }
    }

But when I press the ‘Update’ button from the template and enters in the ‘RowUpdating’ event, the selected value from the dropdownlist is every time the first value from that dropdownlist.

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        DropDownList emailsListDL = (DropDownList)GridViewAdvertisers.Rows[e.RowIndex].FindControl("emailsDL");
        string email = emailsListDL.SelectedValue; //the selected value is every time the first value from the dropdownlist
    }

Does anyone have any ideas?

I’ve tried many ways to set the selected value in the ‘RowDataBound’ event, but with no luck. I tried this:

1. emailsListDL.SelectedIndex = emailsListDL.Items.IndexOf(emailsListDL.Items.FindByValue(DataBinder.Eval(e.Row.DataItem, "OwnerMail").ToString()));
2. emailsListDL.SelectedValue = GridViewAdvertisers.DataKeys[e.Row.RowIndex]["OwnerMail"].ToString();
3. emailsListDL.SelectedValue = GridViewAdvertisers.Rows[e.Row.RowIndex].Cells[1].Text;
//ownerMail is a string (object) from the list of objects that I put as datasource to the gridview

Thanks,
Jeff

Update

My Item template from the aspx page is:

 <asp:TemplateField ItemStyle-HorizontalAlign="Center" ItemStyle-VerticalAlign="Middle"
                ItemStyle-Width="150px" HeaderText="Owner Email" HeaderStyle-HorizontalAlign="Left"
                HeaderStyle-BorderWidth="1px" HeaderStyle-BorderColor="#e1e1e1">
                <ItemTemplate>
                    <asp:Label ID="LabelEmail" runat="server" Text='<%# Bind("OwnerMail")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="emailsDL" runat="server" Width="150">
                    </asp:DropDownList>
                </EditItemTemplate>
                <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Font-Bold="True"></HeaderStyle>
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="180px" BorderWidth="1px"
                    BorderColor="#e1e1e1"></ItemStyle>
    </asp:TemplateField>
  • 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-22T01:30:04+00:00Added an answer on May 22, 2026 at 1:30 am

    The SelectedIndex will always default to 0 if you don’t define it in your DropDownList definition.

    Edit: @Tim Schmelter should add his comment as an anwer. In the meantime, I’ll paraphrase for other readers: You need to check for postback (see comments above).

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

Sidebar

Related Questions

I have an application that uses MSWord automation to edit some documents, after they
I have a Gridview like this picture. Easyly in my last column, i keep
In my application, I use JQGrid for loading some contacts data, and when I
I have Asp.net application that implemented with Dynamic Data technology. All data from my
In my Web Application, i have a data table(Displayed from DB using PreparedStatement). Each
We developed an application to edit the web.config settings. The user has to locate
I have an webView in a Cocoa application which I edit the contents programatically.
----EDIT---- I am making an jquery mobile application. Now I want to check which
When I try to edit texts in my iPhone application ( UITextfield ), it
We have an application that allows users to add/edit/replace/delete content (text, images, swfs, mp3s,

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.