This is a migrated thread and some comments may be shown as answers.

drowdown inside the rad grid

3 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
liju
Top achievements
Rank 1
liju asked on 11 Mar 2011, 03:56 PM
Hi 

I have a rad grid in which i have a status column where I need to bind the current status from the DB. Also near by the item i have a " + " button when clicking on that, it should drop a list of status coming from dbmaster_status. and the user should be able to select a new status and update the db. what is the best option i have inside rad grid. No other button for updating the status.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 14 Mar 2011, 06:53 AM
Hello Liju,

You can attach 'onselectedindexchanged' event to DropDownList (which shows all status). In that event handler get the selected value and get the grid row and key value (to identify which grid row is to update). Then update db with the selected 'status'. Sample code is given below.

ASPX:
<telerik:GridTemplateColumn>
     <ItemTemplate>
         <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" />
     </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
      DropDownList list = (DropDownList)sender;
      string status = list.SelectedValue;
      GridDataItem item = (GridDataItem)list.NamingContainer;
      string keyvalue = item.GetDataKeyValue("ID").ToString();
      //update db with the selected 'status'
  }

Thanks,
Princy.
0
liju
Top achievements
Rank 1
answered on 14 Mar 2011, 07:42 AM
Thanks princy.
 I did like that already after I saw some other thread. but is there a way to update without postback using some web method.
0
Accepted
Princy
Top achievements
Rank 2
answered on 15 Mar 2011, 08:44 AM
Hello Liju,

Here is a sample code that I tried in my application for similar scenario. I have achieved this by invoking the ajaxRequest from 'onchange' client event of DropDownList and saving the row index in AjaxManager_AjaxRequest server event. Then get the corresponding DataItem and access the cell value and update DB.

ASPX:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1". . . . .>
        <Columns>
             <telerik:GridTemplateColumn>
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
  .    .    .    .   .

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           DropDownList list = (DropDownList)item.FindControl("DropDownList1");
           list.Attributes.Add("onchange", "dropdownChange('" + item.ItemIndex + "');");
       }
   }

Java Script:
<script type="text/javascript">
    function dropdownChange(rowindex) {
        var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
        ajaxManager.ajaxRequest(rowindex); // ajaxRequest
    }
    
</script>

C#:
protected void RadAjaxManager1_AjaxRequest1(object sender, AjaxRequestEventArgs e)
   {
       string rowIndex = e.Argument;//getting row index
       GridDataItem item = (GridDataItem)RadGrid1.Items[rowIndex]; //accessing grid item
       //access cell value and update db
   }

Thanks,
Princy.
Tags
Grid
Asked by
liju
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
liju
Top achievements
Rank 1
Share this question
or