开发者

Asp.net GridView BoundColumn Format

开发者 https://www.devze.com 2023-01-17 16:28 出处:网络
Html Code: <asp:DataGrid ID=\"my开发者_如何学PythonGrid\"> <Columns> <asp:BoundColumn DataField=\"CustomerName\" HeaderText=\"Customer\">

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

精彩评论

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