Asp.net GridView BoundColumn Format
Html Code:
<asp:DataGrid ID="my开发者_如何学PythonGrid">
<Columns>
<asp:BoundColumn DataField="CustomerName" HeaderText="Customer">
<ItemStyle Font-Bold="True" />
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
Code Behind:
public string TestFunction(string str)
{
return str.replace("A","B");
}
how to call TestFunction ? DataField="TestFunction(CustomerName)"
Best Regards...
You need to do this in a TemplateColumn:
<asp:DataGrid ID="myGrid">
<Columns>
<TemplateColumn>
<ItemTemplate>
<%# TestFunction(Eval("CustomerName") as string) %>
</ItemTemplate>
</TemplateColumn>
</Columns>
</asp:DataGrid>
This however means you will loose autosorting and editing - but who uses that anyway :)
DataField='<%# TestFunction((string)Eval("MasterDesc")) %>'
UPDATE:
http://forums.asp.net/t/996979.aspx
精彩评论