Click here to Skip to main content
14,421,777 members
Rate this:
Please Sign up or sign in to vote.
See more:
Respected All;

Vins et alcools Chevalier Vins et alcools Chevalier 59 rue de l'Abbaye Brazil Edit | Delete
Toms Spezialitäten Luisenstr. 48 AustraliaAustraliaBrazilBrazilCanadaCanadaDenmarkDenmarkFinlandFinlandFranceFranceGermanyGermanyItalyItalyJapanJapanNetherlandsNetherlandsNorwayNorwaySingaporeSingaporeSpainSpainSwedenSwedenUKUKUSAUSA
Update | Cancel
Hanari Carnes Hanari Carnes Rua do Paço, 67 Austria Edit | Delete
Victuailles en stock Victuailles en stock 2, rue du Commerce France Edit | Delete
Suprêmes délices Suprêmes délices Boulevard Tirou, 255 Belgium Edit | Delete
Hanari Carnes Hanari Carnes Rua do Paço, 67 Brazil Edit | Delete

If i click on edit button in gridview, the dropdownlist with selected item in the list should be displayed. But when im clicking on edit button,items in dropdownlist are displaying not with selected items in the list.
I want to display selected items when i click on edit button.
Rate this:
Please Sign up or sign in to vote.

Solution 1

protected void MainGridView_RowCommand(object sender, GridViewCommandEventArgs e)
 if (e.CommandName == "Edit")
   int introwindex = Convert.ToInt32(e.CommandArgument.ToString());
  Call  you function to bind the Dropdown ;//
  DropDownList drp = MainGridView.Rows[introwindex].FindControl("DrpDown") as DropDownList;
  drp.DataSource=Call  you function to bind the Dropdown ;//
  drp.SelectedItem.Text = myGridView.Rows[introwindex].Cells[1].Text;

Hope this helps!

Senthil S
srikanth.pandu 18-Aug-11 3:07am
Thank you for your response sir,but i want to know can i bind dropdownlist by dataset and datatable also?
And Should i need to write any code under row data bound of gridview?
can u plz help me
Rate this:
Please Sign up or sign in to vote.

Solution 3

You can also do it something like this

in ASPX page
SelectedIndex='<%# SetSelectedIndex(DataBinder.Eval(Container.DataItem, "ItemID")) %>'

In code behind
protected int SetSelectedIndex(object ITEMID)
        int ret = 0;
        List<datatype> lst = get data in a list;
        ret = lst.FindIndex(st => st.ITEMID == Convert.ToInt32(ITEMID));
        return ret;
Rate this:
Please Sign up or sign in to vote.

Solution 2

is it possible in row editing event in gridview?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100