Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
5.00/5 (1 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

C#
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
 
Share this answer
 
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
You can also do it something like this

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

In code behind
C#
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>
 
Share this answer
 
is it possible in row editing event in gridview?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900