Change Text and link in Telerik Radgrid at ITEMDATABOUND event
Change Text and link in Telerik Radgrid at ITEMDATABOUND event
Step 1: Design web form .aspx page
<div>
<asp:ScriptManager ID="sm" runat="server"></asp:ScriptManager>
<telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0" AllowPaging="true" PageSize="8" Width="50%" PagerStyle-AlwaysVisible="true"
GridLines="None" AutoGenerateColumns="false" OnItemDataBound="RadGrid1_ItemDataBound"
OnNeedDataSource="RadGrid1_NeedDataSource">
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
<HeaderStyle HorizontalAlign="Left" />
<MasterTableView DataKeyNames="name" AutoGenerateColumns="false">
<NoRecordsTemplate>No records found.</NoRecordsTemplate>
<Columns>
<telerik:GridBoundColumn HeaderText="Name" DataField="Name" />
<telerik:GridBoundColumn HeaderText="Amount" DataField="Amount" />
<telerik:GridBoundColumn HeaderText="Phone" DataField="Phone" />
<%--<telerik:GridButtonColumn
UniqueName="st" DataTextField="Status"
HeaderText="Status"></telerik:GridButtonColumn>--%>
<telerik:GridHyperLinkColumn UniqueName="status" HeaderText="Status" DataTextField="Status"></telerik:GridHyperLinkColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
Step 2: Logic on .CS Page
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("Name");
dt.Columns.Add("Amount");
dt.Columns.Add("Phone");
dt.Columns.Add("Status");
dt.Rows.Add("Kandy", "12", "8802***2564", "Approved");
dt.Rows.Add("Sam", "25", "545502*2544", "Pending");
dt.Rows.Add("Izhar", "32", "95802*2452", "Pending");
dt.Rows.Add("Vineet", "10.2", "88022564***", "Approved");
RadGrid1.DataSource = dt;
}
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
string status = Convert.ToString(DataBinder.Eval(e.Item.DataItem, "Status"));
GridDataItem item = e.Item as GridDataItem;
if (e.Item is GridDataItem)
{
HyperLink link2 = (HyperLink)item["status"].Controls[0];
if (link2.Text == "Pending")
{
link2.Text = "Kandy Here";
link2.NavigateUrl = "http://kandydeol.blogspot.in/";
}
}
}
Comments
Post a Comment