如何显示数据从文本框到gridview [英] How to display a data from textbox to gridview

查看:76
本文介绍了如何显示数据从文本框到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不与数据库进行数据绑定的情况下显示从文本框到gridview的数据

我已经在asp.net应用程序的源代码部分添加了以下代码

how to display a data from text box to gridview without databounding with the database

i have add the following code in source part in asp.net application

<form id="form1" runat="server">
    <div>

        <table class="style1">
            <tr>
                <td>
                    Name
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
&nbsp; Address&nbsp;
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
&nbsp; Number
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click1" Text="Add" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td>
                    <asp:GridView ID="GridView1" runat="server">
                    </asp:GridView>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
        <br />
        <br />
        <br />
        <br />
        <br />

    </div>
    </form>



现在,当我在以下文本框中输入详细信息时,然后按添加按钮

该信息将在gridview中显示,我在文本框中输入的内容

注意:-文本框值未插入数据库


那么如何显示


提供解决方案



now when i enter the details in following textboxes then when i press add button

the information will be displayed in gridview what i enter in textbox

Note:- textboxes values are not inserted into database


So how it can be displayed


Give u r solution

推荐答案

以下可能是一种方法:
用户单击添加"按钮后,请立即按照以下步骤操作
1.创建一个数据表并创建网格中所有存在的列
2.现在,如果grid不为空,则通过添加新行将所有网格数据插入数据表中(这样,如果grid有3行,则您的数据表将具有3行)
3.新建在数据表中插入文本框数据(现在数据表已第4行)
4.现在,将此数据表设置为数据网格视图的数据源.
希望对您有帮助.

〜Amol
Following can be one approach:
As soon as user clicks on Add button, follow following stapes
1. Crate a data table and create all the columns those are there in the grid
2. Now if grid is not blank then insert all the grid data in the data table by adding new rows (this way if grid has 3 rows then, your data table will have 3 rows)
3. New insert the textbox data in the data table (now data table has got 4th row)
4. Now set this data table as data source for data grid view.
Hope this will help you.

~Amol


Button_Click()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Name");
dt.Columns.Add("Address");
dt.Columns.Add("Number");
//首先填写网格中存在的所有日期
for(int intCnt = 0; intCnt< grd.Rows.Count; intCnt ++)
{
如果(grd.Rows [intCnt] .RowType == DataControlRowType.DataRow)
{
dr = dt.NewRow();
dr ["Name"] = grd.Rows [intCnt] .Cells [0] .Value;
dr ["Address"] = grd.Rows [intCnt] .Cells [1] .Value;
dr ["Number"] = grd.Rows [intCnt] .Cells [2] .Value;
dt.Rows.Add(dr);
}
}
dr = dt.NewRow();
dr ["Name"] = txt1.Text;
dr [地址"] = txt2.Text;
dr ["Number"] = txt3.Text;
dt.Rows.Add(dr);
grd.DataSource = dt;
grd.DataBind();
}

如果我在语法上有任何错误,请进行更正,因为我直接在文本中编写了此代码.

希望现在您的问题能得到解决


〜Amol
Button_Click()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("Name");
dt.Columns.Add("Address");
dt.Columns.Add("Number");
//First fill all the date present in the grid
for (int intCnt = 0; intCnt < grd.Rows.Count; intCnt ++)
{
if (grd.Rows[intCnt].RowType == DataControlRowType.DataRow)
{
dr = dt.NewRow();
dr["Name"] = grd.Rows[intCnt].Cells[0].Value;
dr["Address"] = grd.Rows[intCnt].Cells[1].Value;
dr["Number"] = grd.Rows[intCnt].Cells[2].Value;
dt.Rows.Add(dr);
}
}
dr = dt.NewRow();
dr["Name"] = txt1.Text;
dr["Address"] = txt2.Text;
dr["Number"] = txt3.Text;
dt.Rows.Add(dr);
grd.DataSource = dt;
grd.DataBind();
}

Please make corrections if I made any syntactic mistake because I wrote this code directly in the text.

I hope now your problem will be solved


~Amol


http://www.c-sharpcorner.com/Forums/Thread/48189/display-record-from-gridview-to-textbox.aspx [

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

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