在运行时在GridView中添加行 [英] Add row in GridView at runtime

查看:99
本文介绍了在运行时在GridView中添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两列的网格视图,第一列是包含图像的模板字段,第二列是包含单选按钮的模板字段。



单击时我有一个按钮我想用新图像添加新行,我想在运行时通过代码执行此操作我试过

I have a grid view with two columns, the first one is a template field containing an Image, the second column is a template field containing a radiobutton.

I have a button when clicked I want to Add new row with a new image, I want to do this via code at run time i tried

MyGridView.Rows.Add();

但它不起作用,出现编译错误。

低于代码:

but it's not working, a compilation error comes up.
below the code:

<asp:GridView ID="grd" runat="server" CellPadding="20" ForeColor="#333333" GridLines="None" CellSpacing="10" AutoGenerateColumns="False">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/logo.png" />
    </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Main">
                <ItemTemplate>
                    <asp:RadioButton ID="rbt" runat="server" GroupName="Main" OnClick="javascript:Selrdbtn(this.id)" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        </asp:GridView>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="add" />

推荐答案

根据您的要求。



请参考以下链接..



NewRow GridView [ ^ ]



如果您的查询足够,请将其标记为答案。
As per your requirement.

Please refer following link..

NewRow GridView[^]

Mark it as answer if suffice your query.


参考 - 在GridView中添加新行 [ ^ ]。



它给出了一个简单的例子在 GridView 中添加一行。

请按照说明进行必要的修改以完成任务。
Refer - Adding a New Row in GridView[^].

It gives a simple example of adding a row to GridView.
Please follow that and make necessary modification to complete your task.


这篇关于在运行时在GridView中添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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