如何添加文本框数据网格视图 [英] how to add text box data grid view

查看:125
本文介绍了如何添加文本框数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原件:
单击按钮添加时如何将文本框数据添加到网格视图中,然后dat将显示在网格视图中,以及如何在gridview中搜索值或查找数据

修改日期:
在网格视图中单击添加"按钮时,如何将文本框中的数据添加到网格视图中?
如何在gridview中搜索值或查找数据?

Original:
how to add text boxes data into grid view when button click add then dat will display in grid view and how to search value or find the data in gridview

Modified:
How to add data from text boxes into grid view when add button is clicked in grid view?
How to search value or find the data in gridview?

推荐答案

您将它们添加到模板中以显示数据.您的问题是,然后需要在页面加载之前添加它,以使viewstate起作用.

您从不在网格中搜索,而总是在搜索数据源.

dat不是一个单词.
You add them in your template for how the data is displayed. Your issue is, then need to be added before page load in order for viewstate to work.

You never search in your grid, you always search your data source.

dat is not a word.


Christian正确地将文本框添加到数据网格.以下是可帮助您的代码示例:

Christian is right regarding adding textbox to the datagrid. Below is code sample to help you:

<asp:datagrid id="dg" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
            <columns>
                <asp:boundcolumn datafield="id"></asp:boundcolumn>
                <asp:templatecolumn>
                    <itemtemplate>
                        <asp:textbox id="txt" runat="server" text="<%#DataBinder.Eval(Container.DataItem,"name") %>"></asp:textbox>
                    </itemtemplate>
                </asp:templatecolumn>
            </columns>
        </asp:datagrid>



要读取文本框数据,您需要首先找到每一行的控件.以下示例可能会为您提供帮助:



To read textbox data you need to first find the control for each row. Below sample may help you:

// Loop through the datagrid rows
foreach (DataGridItem item in dg.Items)
{
    // Get textbox corresponding to the row
    TextBox a= item.FindControl("txt") as TextBox;
    if (a != null)
    {
        // Your logic to access the textbox
    }
}



这用于服务器端代码.您还可以在客户端访问网格的控件(建议使用JQuery).



This is for server side code. You can also access the grid''s controls at client side (JQuery recommended).


这篇关于如何添加文本框数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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