Get Row Value on button click in Radgrid
Get Row Value on button click in Radgrid
Step 1: Design web form .aspx page
<div>
<asp:ScriptManager ID="ss" runat="server"></asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" OnNeedDataSource="RadGrid1_NeedDataSource1" Width="50%" OnItemCommand="RadGrid1_ItemCommand"
GridLines="None" PageSize="10">
<MasterTableView TableLayout="Fixed" AutoGenerateColumns="true">
<Columns>
<telerik:GridButtonColumn
CommandName="kandy"
HeaderText="COURSE
NAME"
SortExpression="CourseName"
Text="Button"
ButtonType="LinkButton">
</telerik:GridButtonColumn>
</Columns>
</MasterTableView>
<HeaderStyle Width="100px"></HeaderStyle>
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
</telerik:RadGrid>
</div>
Step 2:Logic on .Cs page
protected void RadGrid1_NeedDataSource1(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Amount");
dt.Columns.Add("Phone");
dt.Rows.Add("Kandy", "12", "8802***2564");
dt.Rows.Add("Sam", "25", "545502*2544");
dt.Rows.Add("Izhar", "32", "95802*2452");
dt.Rows.Add("Vineet", "10.2", "88022564***");
RadGrid1.DataSource = dt;
}
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
if (e.CommandName == "kandy")
{
GridDataItem item = (GridDataItem)e.Item;
string Name = item["name"].Text;
string Phone = item["Phone"].Text;
string Amount = item["Amount"].Text;
Response.Write(Name + " : " +
Amount + "
: " + Phone);
}
}
Comments
Post a Comment