GridView column populated by method.

SteveInBeloit

Well-known member
Joined
May 22, 2006
Messages
132
Programming Experience
10+
Hi,
I dragged a Gridview onto the page, and in the code, set the DataSource and did the DataBind. That all went well. For one of the columns, I want to populate by calling a method passing it the original value from the datasource.
How can I do this?
Thanks
 
Try something like this.

VB.NET:
Expand Collapse Copy
<asp:TemplateField HeaderText="ColumnName">
    <ItemTemplate>
        <%#CallStatus(CType(CType(Container.DataItem, System.Data.DataRowView).Row, DataSetName.DataTableNameRow))%>
    </ItemTemplate>
</asp:TemplateField>

For the code behind.

VB.NET:
Expand Collapse Copy
Protected Function CallStatus(ByVal status As DataSetName.DataTableNameRow) As String
    ...
End Function
 
Matt,
Thanks, you got me going down the right path by looking at your code. Here is what I ended up with that works:

VB.NET:
Expand Collapse Copy
  <ItemTemplate>
          <asp:Label ID="Label2" runat="server" Text = '<%# ShowGroupBenefit(Container.DataItem) %>'></asp:Label>
  </ItemTemplate>
 
Back
Top