Thursday, June 4, 2015

Make a GridViewDataColumn show some HTML and not just the Caption setting at a DevExpress ASPxGridView.

<dx:GridViewDataColumn FieldName="MerchantName" VisibleIndex="1">
   <GroupRowTemplate>
      <a href="Whatever.aspx"><%# Eval("MerchantName") %></a>
   </GroupRowTemplate>
</dx:GridViewDataColumn>

 
 

...or, if you need something smarter than a hyperlink...

<dx:GridViewDataColumn FieldName="MerchantName" VisibleIndex="1">
   <DataItemTemplate>
      <asp:LinkButton ID="MerchantLink" runat="server" CommandName="ViewMerchant"
            CausesValidation="false" Text='<%# Eval("MerchantName")%>'>
      </asp:LinkButton>
   </DataItemTemplate>
</dx:GridViewDataColumn>

 
 

For the later, you will need to wire up an event like so:

MyGrid.RowCommand += MyGrid_RowCommand;

 
 

...and then make it do stuff in C# like this:

void MyGrid_RowCommand(object sender, ASPxGridViewRowCommandEventArgs e)
{

 
 

Note that the GroupIndex="0" setting will sabotage the DataItemTemplate stuff, keeping it from working.

Addendum 8/28/2015: You're going to need a tag like so...

<SettingsBehavior AutoExpandAllGroups="True"></SettingsBehavior>

 
 

...just inside the ASPxGridView tag and you will want GroupIndex="0" inside of the GridViewDataColumn tag in spite of what I say above.

No comments:

Post a Comment