Dropdownlist, EditCommand in datagrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jhcorey@yahoo.com

    Dropdownlist, EditCommand in datagrid

    I've been googling this and know it's been covered often, but I can't
    get mine to work.

    I'm using a dropdown list when editing the record in the datagrid.
    I'm testing this using an arraylist to populate the dropdown.

    The problem is in selecting the item in the dropdown that corresponds
    to
    the current record's value.

    I have the function below wired to the EditCommand event. I'm looking
    for the simplest way to select the correct value in the dropdownlist.
    I notice in the OnItemDataBound I
    have to cast the item cells to textboxes when the item is being edited,
    but I'm not sure how to find the value I need.

    private void dg_Columns_Edit (object source,
    System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
    {
    dg_Columns.Edit ItemIndex = e.Item.ItemInde x;
    rptDataTypes = new ArrayList();
    rptDataTypes.Ad d("DESC");
    rptDataTypes.Ad d("ASC");

    FillColumnGrid( );
    DropDownList dl =

    ((DropDownList) dg_Columns.Item s[e.Item.ItemInde x].Cells[5].FindControl("d dlSortDir"));
    dl.DataSource = rptDataTypes;
    dl.DataBind();

    }

  • Patrick.O.Ige

    #2
    Re: Dropdownlist, EditCommand in datagrid

    jhcorey,
    Try looking at this sample at:-
    eSports News, Results, upcoming Matches & live Matches. Learn tricks and guides in the esports space. ✅ We cover CS:GO, Dota 2, LOL, Overwatch & PUBG. 

    It should guide you.
    Patrick


    <jhcorey@yahoo. com> wrote in message
    news:1131458539 .023988.252400@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    > I've been googling this and know it's been covered often, but I can't
    > get mine to work.
    >
    > I'm using a dropdown list when editing the record in the datagrid.
    > I'm testing this using an arraylist to populate the dropdown.
    >
    > The problem is in selecting the item in the dropdown that corresponds
    > to
    > the current record's value.
    >
    > I have the function below wired to the EditCommand event. I'm looking
    > for the simplest way to select the correct value in the dropdownlist.
    > I notice in the OnItemDataBound I
    > have to cast the item cells to textboxes when the item is being edited,
    > but I'm not sure how to find the value I need.
    >
    > private void dg_Columns_Edit (object source,
    > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
    > {
    > dg_Columns.Edit ItemIndex = e.Item.ItemInde x;
    > rptDataTypes = new ArrayList();
    > rptDataTypes.Ad d("DESC");
    > rptDataTypes.Ad d("ASC");
    >
    > FillColumnGrid( );
    > DropDownList dl =
    >
    >[/color]
    ((DropDownList) dg_Columns.Item s[e.Item.ItemInde x].Cells[5].FindControl("d dlS
    ortDir"));[color=blue]
    > dl.DataSource = rptDataTypes;
    > dl.DataBind();
    >
    > }
    >[/color]


    Comment

    Working...