开发者

How to put more control in each single cell of the grid view Control

I am using grid view control in my web application.Here i need to make 开发者_如何学Golabel ,image and button controls into each single cell of grid view control.how to put controls into single cell.


You can use TemplateField to place multiple controls inside single cell:

<asp:GridView ID="grdView">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="btn" />
                        <asp:Label ID="lbl" />
                        ....
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

Later in your code behind you can retrieve them using their id, you first have to get the reference to the individual row:

for (int i = 0; i < grdView.Rows.Count; i++)
        {
            if (grdView.Rows[i].RowType == DataControlRowType.DataRow)
            {
                Button objBtn = (Button)grdView.Rows[i].FindControl("btn"); //btn must match with the id defined in aspx page
                Label objLbl = (Label)grdView.Rows[i].FindControl("lbl"); .....
            }
        }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜