在运行时添加具有就地编辑功能的GridView控件 [英] Adding a GridView control with in-place editing features during Run Time

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

问题描述

protected void Page_Load(object sender, EventArgs e)
    {
        string s = //some other functions to assign
        GridView gvGenInfo = new GridView();
        gvGenInfo.AutoGenerateColumns = true;

        if (s.Equals("Address"))
        {
           gvGenInfo.Columns.Add(//Street Name colums);
           gvGenInfo.Columns.Add(//Postal code column);
        }
        else if (s.Equals("Person"))
        {
           gvGenInfo.Columns.Add(//Name colums);
           gvGenInfo.Columns.Add(//Gender column);

        }
        DataTable dt = GetData();


        //add inserting, editing template for GridView

        gvGenInfo.DataSource = dt;
        gv.DataBind();
    }



对于插入,页脚模板中需要使用添加"按钮来添加一些文本框.单击添加后,数据将添加到gridview.

为了进行编辑,用户将单击编辑"列中的编辑"超链接,文本框将出现在相应行中,以供用户更新新数据.更新后,单击更新"链接标签,并在GridView上更新新数据.

如何在运行时实现添加页脚模板和编辑模板?另外,当每次插入,编辑和更新操作都产生回发时,如何解决无状态问题?

执行此操作的基本原理是生成动态数据输入控件,以供用户输入,更新数据.表单控件的信息存储在后端数据存储中,并在运行时加载.因此,可以动态控制Web表单.但是我找不到一种方法来克服页面回发时控件丢失的问题.



For insertion, some textboxes are required in the footer template with an "Add" button. On clicking add, the data is added to the gridview.

For editing, users will click a "Edit" hyperlink in the Edit column and textboxes appear in the corresponding row for users to update new data. Upon update, click Update link label and new data updated on GridView.

How can I achieve adding footer templates and editing templates during run-time? Also how can I over come the stateless issue when each insert, edit and update operation incurs a postback?

The rationale for performing this is to produce a dynamic data entry controls for users to enter, update data. The information of form controls are stored on backend data store and loaded on run-time. Thus, the dynamic controls on web forms. But I can''t find a way to overcome the lost of controls upon page postback.

推荐答案

我认为下面的链接将帮助您很多了解GridView和页脚模板....

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/gridview.aspx

不用在gridviews页脚模板中创建数据输入表单,而是使用formview(您也可以在上面的URL中获得示例)
I think the following link will help you a lot to understand GridView and footer template....

http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/gridview.aspx

Instead of creating the data entry form in the gridviews footer template use formview (you can also get an example in the above URL)


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

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