Hi,
I have a rad grid which has three columns ie, one link button and two labels. Link button should be enabled based on some logic. So i did this in
OnItemDataBound of the RadGrid and it was working fine when the page loads first time. But when i do any sorting by clicking on one of the columns
the link enabling and disabling logic doesnt reflect in UI. Ie, the first column not getting binded after OnItemDataBound.
.aspx.cs:
protected void radgrid1_OnNeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
FillGrid();
}
protected void radgrid1_OnItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
LinkButton btnView = (LinkButton)item.FindControl("btnView");
DataRowView v = (DataRowView)e.Item.DataItem;
string Quotation_no = v.DataView[e.Item.ItemIndex]["Quotation_no"].ToString();
string str= btnView.Enabled.ToString();
if (Quotation_no.Trim().Equals("1"))
{
btnView.Enabled = false;
btnView.Text = Quotation_no + "gg";
}
else
{
btnView.Enabled = true;
btnView.Text = Quotation_no + "mm";
}
}
}
.aspx:
<telerik:RadGrid runat="server" ID="radgrid1" AutoGenerateColumns="False" AllowSorting="true"
AllowPaging="true" OnNeedDataSource="radgrid1_OnNeedDataSource" OnItemDataBound="radgrid1_OnItemDataBound"
OnSortCommand="radGrid1_SortCommand">
<MasterTableView Width="100%" PagerStyle-AlwaysVisible="true" EnableNoRecordsTemplate="true"
ShowHeadersWhenNoRecords="false">
<NoRecordsTemplate>
No Data Found.
</NoRecordsTemplate>
<Columns>
<telerik:GridTemplateColumn UniqueName="Quotation_no" HeaderText="Quotation_no">
<ItemTemplate>
<asp:LinkButton ID="btnView" runat="server"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="lob_desc" HeaderText="Decription" SortExpression="lob_desc">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("lob_desc") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="lob_desc" HeaderText="Units" SortExpression="UNITS">
<ItemTemplate>
<asp:Label ID="lblUnits" runat="server" Text='<%# Eval("UNITS") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<PagerStyle AlwaysVisible="True"></PagerStyle>
</MasterTableView>
</telerik:RadGrid>
I have a rad grid which has three columns ie, one link button and two labels. Link button should be enabled based on some logic. So i did this in
OnItemDataBound of the RadGrid and it was working fine when the page loads first time. But when i do any sorting by clicking on one of the columns
the link enabling and disabling logic doesnt reflect in UI. Ie, the first column not getting binded after OnItemDataBound.
.aspx.cs:
protected void radgrid1_OnNeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
FillGrid();
}
protected void radgrid1_OnItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
LinkButton btnView = (LinkButton)item.FindControl("btnView");
DataRowView v = (DataRowView)e.Item.DataItem;
string Quotation_no = v.DataView[e.Item.ItemIndex]["Quotation_no"].ToString();
string str= btnView.Enabled.ToString();
if (Quotation_no.Trim().Equals("1"))
{
btnView.Enabled = false;
btnView.Text = Quotation_no + "gg";
}
else
{
btnView.Enabled = true;
btnView.Text = Quotation_no + "mm";
}
}
}
.aspx:
<telerik:RadGrid runat="server" ID="radgrid1" AutoGenerateColumns="False" AllowSorting="true"
AllowPaging="true" OnNeedDataSource="radgrid1_OnNeedDataSource" OnItemDataBound="radgrid1_OnItemDataBound"
OnSortCommand="radGrid1_SortCommand">
<MasterTableView Width="100%" PagerStyle-AlwaysVisible="true" EnableNoRecordsTemplate="true"
ShowHeadersWhenNoRecords="false">
<NoRecordsTemplate>
No Data Found.
</NoRecordsTemplate>
<Columns>
<telerik:GridTemplateColumn UniqueName="Quotation_no" HeaderText="Quotation_no">
<ItemTemplate>
<asp:LinkButton ID="btnView" runat="server"></asp:LinkButton>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="lob_desc" HeaderText="Decription" SortExpression="lob_desc">
<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("lob_desc") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="lob_desc" HeaderText="Units" SortExpression="UNITS">
<ItemTemplate>
<asp:Label ID="lblUnits" runat="server" Text='<%# Eval("UNITS") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<PagerStyle AlwaysVisible="True"></PagerStyle>
</MasterTableView>
</telerik:RadGrid>