gridview绑定,同时循环for循环 [英] gridview binding while looping through for loop

查看:129
本文介绍了gridview绑定,同时循环for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个像

Hi I have a grid like

<asp:GridView ID="grdType" runat="server" HeaderStyle-CssClass="grdheadercss" AutoGenerateColumns="false">
    <Columns>
        <asp:TemplateField HeaderText="Name" ItemStyle-CssClass="gridColCSS" ItemStyle-HorizontalAlign="Center" HeaderStyle-ForeColor="#575d16">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Type.AmendmentType.Name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Total" ItemStyle-CssClass="gridColCSS" ItemStyle-HorizontalAlign="Center" HeaderStyle-ForeColor="#575d16">
            <ItemTemplate>
                <asp:Label runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Value") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate></ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>



从数据源绑定数据后,我想循环遍历ea ch row并在第3个TempleteField插入一个不同的值。



我该怎么做?请帮助。


After binding the data from datasource, I want to loop through each row and insert a different value in 3rd TempleteField.

How can I do this? Kindly Help.

推荐答案

使用grodview的RowDataBound事件,该事件为此方法中的每一行触发,您可以根据您的要求自定义单元格。
Use RowDataBound event of the grodview which is fired for each row in this method you can customize the cells based on your requirement.


只是为了支持, Brij 说什么......

Just to support, what Brij said...
protected void grdType_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if(e.Row.RowType == DataControlRowType.DataRow)
    {
        // Find the TemplateField here and do whatever you want to do.
    }
}


这篇关于gridview绑定,同时循环for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆