开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜