Add DataItemTemplate to Grid Column to access at server side code. In case of DataRowTemplate, we create template for whole row, but if we want to create template for a single column then we use DataItemTemplate and on the place of DataRowTemplate’s
((sender as ASPxGridView).FindRowTemplateControl(..) method; here we use FindRowCellTempleteControl(..) method on HtmlRowCreated event of ASPxGridView.
Grid Markup:
((sender as ASPxGridView).FindRowTemplateControl(..) method; here we use FindRowCellTempleteControl(..) method on HtmlRowCreated event of ASPxGridView.
Grid Markup:
<dx:ASPxGridView ID="grvTest" AutoGenerateColumns="False" runat="server" DataSourceID="SqlDataSource1"
OnHtmlRowPrepared="grvTest_HtmlRowPrepared" OnHtmlRowCreated="grvTest_HtmlRowCreated">
<Columns>
<dx:GridViewDataTextColumn Caption="RowID" Name="colRowID" VisibleIndex="0" Width="20px">
<DataItemTemplate>
<dx:ASPxLabel ID="lblRowID" runat="server" Text='Label'>
</dx:ASPxLabel>
</DataItemTemplate>
</dx:GridViewDataTextColumn>
C#
protected void grvTest_HtmlRowCreated(object sender, ASPxGridViewTableRowEventArgs e)
{
if (e.RowType != GridViewRowType.Data) return;
ASPxLabel label = grvTest.FindRowCellTemplateControl(e.VisibleIndex, null,
"lblRowID") as ASPxLabel;
label.Text = (e.VisibleIndex + 1).ToString();
}
This comment has been removed by the author.
ReplyDeleteHow can i get the text of the next example?
ReplyDeletedx:GridViewDataTextColumn Width="100px" Caption="" FieldName="modulo" Visible="false"
DataItemTemplate
table cellpadding="0" cellspacing="0"
tr
td style=" text-align:right;"
asp:Label ID="lblModulo" runat="server" Text=""
asp:Label
td
tr
table
DataItemTemplate
dx:GridViewDataTextColumn
Thanks, It's really helpful code for me. i was looking for the same solution
ReplyDeleteBut the label value is coming null
ReplyDelete