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

Selected row cell value in raggrid

2 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sho
Top achievements
Rank 1
sho asked on 04 Aug 2011, 09:49 AM
Hi,

My aspx page has radgrid and a dropdownlist. I want to populate this dropdownlist based on the value captured from a cell on selecting a single radgrid row.

I have set AllowMultiRowSelection ="false"  and on clientsettings <Selecting AllowRowSelect="True"></Selecting>.

How can I do this?

Or if am using <ClientEvents OnRowSelected="RowSelected" /> and call some javascript I can get the cell value. How will I make use of this to populate the dropdown. The dropdown population is in codebehind.

Thanks,

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Aug 2011, 10:23 AM
Hello,

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnNeedDataSource="RadGrid1_NeedDataSource"
           OnItemCommand="RadGrid1_ItemCommand">
           <MasterTableView  DataKeyNames="ID">
               <Columns>
                   <telerik:GridBoundColumn UniqueName="ID" HeaderText="ID" DataField="ID">
                   </telerik:GridBoundColumn>
               </Columns>
           </MasterTableView>
           <ClientSettings EnablePostBackOnRowClick="true">
               <Selecting AllowRowSelect="true" />
           </ClientSettings>
       </telerik:RadGrid>
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "RowClick" && e.Item is GridDataItem)
        {
            string strIdColumnText = ((GridDataItem)e.Item)["ID"].Text;
            // e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"]; // You can also take Id from DataKey
            BindCombo(strIdColumnText);
        }
    }
 
    protected void BindCombo(string strValue)
    {
        // Bind your combo here
    }

let me know if this is not your case.

Thanks,
Jayesh Goyani
0
Shinu
Top achievements
Rank 1
answered on 04 Aug 2011, 03:35 PM
Hello sho,

Try the following scenario using RadAjaxManager to populate DropDownList.
JS:
<script type="text/javascript">
function RowSelected(sender, eventArgs)
{
    var grid = sender;
    var MasterTable = grid.get_masterTableView(); var row = MasterTable.get_dataItems()[eventArgs.get_itemIndexHierarchical()];
    var cell = MasterTable.getCellByColumnUniqueName(row, "EmployeeID");
    $find("<%=RadAjaxManager1.ClientID%>").ajaxRequest(cell.innerHTML);
}
</script>
aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
</telerik:RadAjaxManager>
C#:
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
   string val=e.Argument;
   binddropdown();
}
protected void binddropdown(string strvalue)
  {
     //Bind your dropdown here
  }

Thanks,
Shinu.
Tags
Grid
Asked by
sho
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Shinu
Top achievements
Rank 1
Share this question
or