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

Retrieving a value from a selected Row

2 Answers 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 18 Aug 2008, 09:46 PM
Hello,

I am new to RadGrid and have a pretty basic problem that I cannot solve. I have a RadGrid set up with a Select command (code below) when a User clicks on the Select link I want to be able to retrieve the Userid ( a column in the row) and do some additional processing. How can I
1) Tell which row was selected
2) Get a particular Cell value in this case UserId

Code:

          <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" GridLines="None"   
                    PageSize="2" onitemcreated="RadGrid1_ItemCreated" width="97%"  AllowMultiRowSelection="false" 
                  OnItemCommand="RadGrid1_ItemCommand" AutoGenerateColumns="False"   
                  Skin="WebBlue" onselectedindexchanged="RadGrid1_SelectedIndexChanged" > 
                  <ClientSettings > 
                  
            </ClientSettings> 
              
 
<PagerStyle Mode="NextPrevAndNumeric" /> 
<MasterTableView PageSize="2" > 
   <Columns> 
   <telerik:GridButtonColumn Text="Select" CommandName="Select">  
                        </telerik:GridButtonColumn> 
    <telerik:GridBoundColumn DataField="UserId" HeaderText="UserID" HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center"  /> 
    <telerik:GridBoundColumn DataField="FirstName" HeaderText="First Name" HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center"/>  
    <telerik:GridBoundColumn DataField="LastName" HeaderText="Last Name" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn DataField="Username" HeaderText="Username" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" /> 
    <telerik:GridBoundColumn DataField="Role" HeaderText="Role" HeaderStyle-HorizontalAlign="Center"  ItemStyle-HorizontalAlign="Center"/>  
   </Columns> 
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
</MasterTableView> 
</telerik:RadGrid> 

2 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 18 Aug 2008, 11:05 PM
Never Mind I figuered it out :

 if (e.CommandName == "Select" && e.Item is GridDataItem)  
            {  
                GridDataItem gridDataItem = e.Item as GridDataItem;  
 
                  
                e.Item.Selected = true;  
                UserID = Convert.ToInt32(gridDataItem["Userid"].Text);  
                string user = gridDataItem["Username"].Text;  
                PopData(user);  
                return;  
 
 
            } 
0
Shinu
Top achievements
Rank 1
answered on 19 Aug 2008, 09:31 AM
Hi mgaughan,

You can also try accessing the selected text in the SelectedIndexChanged event of the Grid as shown below.

CS:
  protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.SelectedItems) 
        { 
            string strSelectedText = item["Username"].Text.ToString(); 
        }  
    } 


ASPX:
 <ClientSettings  EnablePostBackOnRowClick="true" > 
             </ClientSettings> 
 

Thanks
Shinu.
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or