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;

10248
Vins et alcools Chevalier Vins et alcools Chevalier 59 rue de l'Abbaye Brazil Edit | Delete
10249
Toms Spezialitäten Luisenstr. 48 AustraliaAustraliaBrazilBrazilCanadaCanadaDenmarkDenmarkFinlandFinlandFranceFranceGermanyGermanyItalyItalyJapanJapanNetherlandsNetherlandsNorwayNorwaySingaporeSingaporeSpainSpainSwedenSwedenUKUKUSAUSA
Update | Cancel
10250
Hanari Carnes Hanari Carnes Rua do Paço, 67 Austria Edit | Delete
10251
Victuailles en stock Victuailles en stock 2, rue du Commerce France Edit | Delete
10252
Suprêmes délices Suprêmes délices Boulevard Tirou, 255 Belgium Edit | Delete
10253
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.
Posted
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.DataBind();  
  drp.SelectedItem.Text = myGridView.Rows[introwindex].Cells[1].Text;
 }
}


Hope this helps!

Senthil S
   
Comments
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;
    }</datatype>
   
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