如何通过gridview中的文本框将值保存到数据库中并获取它... [英] How to save value into database through textbox which is in gridview and fetch it...

查看:71
本文介绍了如何通过gridview中的文本框将值保存到数据库中并获取它...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gridview中使用了文本框,想在数据库中保存文本框值,然后在gridview本身的文本框中获取它



//源代码



I have taken textbox in gridview and want to save textbox value in database and then fetch it in textbox of gridview itself

//source code

<asp:GridView ID="GrdATCart" AutoGenerateColumns="false" runat="server"

            onrowcommand="GrdATCart_RowCommand"

            onselectedindexchanged="GrdATCart_SelectedIndexChanged">
    <Columns>
        <asp:TemplateField HeaderText="Quantity">
            <ItemTemplate>
                <asp:TextBox ID="TxtATquantity" runat="server" Width="60px"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>

推荐答案

您好,



点按此按钮并获取值来自文本框



Hi,

Try this on button click and fetch value from textbox

foreach (GridViewRow row in gridview1.Rows) 
        {
            if (row.RowType == DataControlRowType.DataRow) 
            {
                Textbox txt = (Textbox) row.FindControl("txt1");
                if (txt != null )
                {
                    string value=txt.Text;
//Here you can write your query to insert into database
                }
            }
        }


请按照这篇文章:



< a href =http://www.codeproject.com/Articles/249429/Frequently-Asked-Questions-Series-1-The-ASP-Net-Gr#heading0004> CodeProject常见问题系列1:ASP.NET GridView [ ^ ]
Please, follow this article:

CodeProject Frequently Asked Questions Series 1: The ASP.NET GridView[^]


请点击以下链接:



使用ASP.NET GridView中的事件实现累计总计和选择所有功能 [< a href =http://www.codeproject.com/Articles/487502/Implementing-Cumulative-total-and-Select-All-功能target =_ blanktitle =新窗口> ^ ]
Please follow the link below:

Implementing Cumulative total and Select All functionality with Events in ASP.NET GridView[^]


这篇关于如何通过gridview中的文本框将值保存到数据库中并获取它...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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