Sropdown selected value in edit mode (Radgrid)

7 posts, 0 answers
  1. Jagat
    Jagat avatar
    135 posts
    Member since:
    Jan 2011

    Posted 28 Oct 2011 Link to this post


    Hi,

    I want to use dropdowns in a radgrid.

    When i enter into edit mode, i want to show the selected value in the dropdown .

    How can i do this?
    So far this is my code.

    Thanks




    <telerik:GridTemplateColumn HeaderText="City">
                            <ItemTemplate>
                                <asp:Label ID="lblcity" runat="server" Text='<%# Bind("CityID") %>'></asp:Label>
                              
                                  
                            </ItemTemplate>
                            <EditItemTemplate>
                              
                                <asp:DropDownList ID="ddlCity" runat="server">
                                </asp:DropDownList>
                              
                              
                            </EditItemTemplate>
                              
                              
                            </telerik:GridTemplateColumn>




    Code Behind:

    protected void gdv_Drivers_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
           {
                
               if ((e.Item is GridEditableItem && ((GridEditableItem)e.Item).IsInEditMode))
               {
                   string where = null;
                 //  string cityid = ((DropDownList)e.Item.FindControl("ddlcity")).SelectedValue;
                 //  string stateid = ((DropDownList)e.Item.FindControl("ddlstate")).SelectedValue;
                 //  string zipid = ((DropDownList)e.Item.FindControl("ddlzip")).SelectedValue;
                   DropDownList ddlcity, ddlstate, ddlzip;
                   ddlcity = ((DropDownList)e.Item.FindControl("ddlCity"));
                   ddlstate = ((DropDownList)e.Item.FindControl("ddlState"));
                   ddlzip = ((DropDownList)e.Item.FindControl("ddlZip"));
                   myGlobal.LoadDropDown(ddlcity, "tbl_CityLkup", "CityID", "CityNm", "GCRPC", "CityID", "CityNm", where);
                   myGlobal.LoadDropDown(ddlstate, "tbl_StateLkup", "StateID", "StateNm", "GCRPC", "StateID", "StateNm", where);
                   myGlobal.LoadDropDown(ddlzip, "tbl_ZipLkup", "ZipID", "ZipCd", "GCRPC", "ZipID", "ZipCd", where);
                             
                 
               }
                
           }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Oct 2011 Link to this post

    Hello Jagat,

    You can attach SelectedIndexChanged event to the DropDownList and access the selected value as shown below.

    aspx:
    <EditItemTemplate>
         <asp:DropDownList ID="ddlAccountLookup" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlAccountLookup_SelectedIndexChanged">
         </asp:DropDownList>
    </EditItemTemplate>

    C#:
    protected void ddlAccountLookup_SelectedIndexChanged(object sender, EventArgs e)
    {
       DropDownList ddl = (DropDownList)sender;
       GridEditableItem item = (GridEditableItem)ddl.NamingContainer;
       string str = ddl.SelectedValue;
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jagat
    Jagat avatar
    135 posts
    Member since:
    Jan 2011

    Posted 02 Nov 2011 Link to this post

    Hi Shinu,

    This event does not fire at all

    Edit: Ignore this post. See my next post.
  5. Jagat
    Jagat avatar
    135 posts
    Member since:
    Jan 2011

    Posted 02 Nov 2011 Link to this post

    Shinu,

    If when the grid loads teh city name for the first row is New York.
    When i edit this row, the dropdown list should display "New York" in that row. Then the user wil lselect to change to any other value he wants.

    Right now, dropdown is populated, but it is not showing the current value when it goes into edit mode.
  6. Russ
    Russ avatar
    49 posts
    Member since:
    Sep 2006

    Posted 02 Nov 2011 Link to this post

    In vb.net it would be

    ddlCity.SelectedValue = directcast(e.item.DataItem, DataRowView).Item("City")

    In C#:

    ddlCity.SelectedValue = (DataRowView)e.item.DataItem["City"];
  7. Jagat
    Jagat avatar
    135 posts
    Member since:
    Jan 2011

    Posted 02 Nov 2011 Link to this post

    Russ,

    Which event should i have it in?
    I tried in edit_command, itemdatabound events.


    I am getting this error message:

    'Telerik.Web.UI.GridItemEventArgs' does not contain a definition for 'item' and no extension method 'item' accepting a
    first argument of type 'Telerik.Web.UI.GridItemEventArgs' could be found (are you missing a using directive or an assembly reference?) 

     

  8. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Nov 2011 Link to this post

    Hello Jagat,

    You can take a look into the following documentation.
    Operations with MS DropDownList in EditItemTemplate of GridTemplateColumn

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017