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

RagGRID DataTextField

1 Answer 107 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ravi Prasad Potturi
Top achievements
Rank 1
Ravi Prasad Potturi asked on 05 Sep 2008, 11:36 PM
Hi,

         I am very beginer using rad controls. I have a situation where i want to display the data in grid and need to provide the link to key filed. I need to display the details in new web page when user selet the link in the grid. I am not really sure how i can capture the key field associated to link. below is my code. Can you please help me on this?


Thanks
RP

<

telerik:RadGrid ID="grdDealerList" runat="server"

AllowPaging="True" AllowSorting="True" GridLines="None" PageSize="10" ShowStatusBar="true" OnItemCommand="RadGrid1_ItemCommand" >

<PagerStyle Mode="NumericPages" />

<MasterTableView Width="100%" >

<Columns>

<telerik:GridButtonColumn DataTextField="DEALER_NUM" CommandArgument="DEALER_NUM" HeaderText="Dealer Number" CommandName="Select">

</telerik:GridButtonColumn>

<telerik:GridHyperLinkColumn

DataNavigateUrlFields= "DEALER_NUM,ROW_ID"

DataNavigateUrlFormatString= "~/Details.aspx?DealerNum={0}&RowID={1}" DataTextField="DEALER_NUM">

</telerik:GridHyperLinkColumn>

</Columns>

</MasterTableView>

<ClientSettings EnablePostBackOnRowClick="true" >

<Selecting AllowRowSelect="True" ></Selecting>

</ClientSettings>

</telerik:RadGrid>

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 08 Sep 2008, 05:30 AM
Hello Ravi,

Try the following code in the ItemCommand event to set the datakeyfield as the parameter to be passed.
aspx:
<MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="DEALER_NUM">  
</MasterTableView>  

cs:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        if (e.CommandName == "Select")  
        {  
            GridDataItem dataItem = (GridDataItem)e.Item;  
            string strTxt = dataItem.GetDataKeyValue("DEALER_NUM").ToString();  
            Response.Redirect("Default.aspx?DEALER_NUM=" + strTxt + "");  
        }  
    }  

Princy.
Tags
Grid
Asked by
Ravi Prasad Potturi
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or