有人知道如何在Gridview中修改值吗? [英] Anyone know how to modify values in Gridview?

查看:74
本文介绍了有人知道如何在Gridview中修改值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是ASP.NET的初学者.
我在Web窗体中有一个Gridview.前三列是从SQL绑定的.
我想在文本框中输入条形码,然后按Enter.
它将比较第3列中Barcode1的值.
如果匹配,则Barocde1的值将显示在Scan1中.
然后是Barcode2,Barcode3 ...直到最后一行.

还是有更好的方法可以找到.


以下是我的问题代码.

Hi,
I am a beginner in ASP.NET.
I have a Gridview in a Web Form. The first 3 columns are binding from SQL.
I''d like to enter a barcode in the TextBox and then Enter.
It will compare the value of Barcode1 in column 3.
If it matches, then the value of Barocde1 will be showed in Scan1.
Then Barcode2, Barcode3...until the last row.

Or is there any better way to do it will be find.


Below is the code of my question.

<![CDATA[<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridPage.aspx.vb" Inherits="GridPage" %>]]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="style1">
            <tr>
                <td>
                    <asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
                        DataKeyNames="No" DataSourceID="SqlDataSource1"&gt;
                        <columns>
                            <asp:boundfield datafield="No" headertext="No" readonly="True">
                                SortExpression="No" /&gt;
                            <asp:boundfield datafield="Item" headertext="Item" sortexpression="Item" />
                            <asp:boundfield datafield="Barcode" headertext="Barcode">
                                SortExpression="Barcode" /&gt;
                            <asp:templatefield headertext="Scan"></asp:templatefield>
                        </asp:boundfield></asp:boundfield></columns>
                    </asp:gridview>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:textbox id="TextBox1" runat="server" xmlns:asp="#unknown"></asp:textbox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:sqldatasource id="SqlDataSource1" runat="server" xmlns:asp="#unknown">
                        ConflictDetection="CompareAllValues"
                        ConnectionString="&lt;%$ ConnectionStrings:TestDbaConnectionString %&gt;"
                        DeleteCommand="DELETE FROM [TestChecklist] WHERE [No] = @original_No AND (([Item] = @original_Item) OR ([Item] IS NULL AND @original_Item IS NULL)) AND (([Barcode] = @original_Barcode) OR ([Barcode] IS NULL AND @original_Barcode IS NULL))"
                        InsertCommand="INSERT INTO [TestChecklist] ([No], [Item], [Barcode]) VALUES (@No, @Item, @Barcode)"
                        OldValuesParameterFormatString="original_{0}"
                        SelectCommand="SELECT [No], [Item], [Barcode] FROM [TestChecklist]"
                        UpdateCommand="UPDATE [TestChecklist] SET [Item] = @Item, [Barcode] = @Barcode WHERE [No] = @original_No AND (([Item] = @original_Item) OR ([Item] IS NULL AND @original_Item IS NULL)) AND (([Barcode] = @original_Barcode) OR ([Barcode] IS NULL AND @original_Barcode IS NULL))"&gt;
                        <deleteparameters>
                            <asp:parameter name="original_No" type="Int16" />
                            <asp:parameter name="original_Item" type="String" />
                            <asp:parameter name="original_Barcode" type="String" />
                        </deleteparameters>
                        <insertparameters>
                            <asp:parameter name="No" type="Int16" />
                            <asp:parameter name="Item" type="String" />
                            <asp:parameter name="Barcode" type="String" />
                        </insertparameters>
                        <updateparameters>
                            <asp:parameter name="Item" type="String" />
                            <asp:parameter name="Barcode" type="String" />
                            <asp:parameter name="original_No" type="Int16" />
                            <asp:parameter name="original_Item" type="String" />
                            <asp:parameter name="original_Barcode" type="String" />
                        </updateparameters>
                    </asp:sqldatasource>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>



[修改:添加了前置标记]



[Modified: added pre tags]

推荐答案

ConnectionStrings:TestDbaConnectionString%& gt; DeleteCommand ="DELETE FROM [TestChecklist] WHERE [No] = @original_No AND(([[Item] = @original_Item)OR([[Item] IS NULL AND @original_Item IS NULL)))AND(([[Barcode] = @original_Barcode)OR ([[条形码]为NULL和@original_Barcode为NULL)) InsertCommand ="INSERT INTO [TestChecklist]([否],[Item],[Barcode])VALUES(@ No,@ Item,@ Barcode)" OldValuesParameterFormatString ="original_ {0}" SelectCommand =从[TestChecklist]中选择[否],[项目],[条形码]" UpdateCommand ="UPDATE [TestChecklist] SET [商品] = @商品,[条形码] = @条形码WHERE [否] = @original_No AND(([商品] = @original_Item)或([商品]是NULL和@original_Item是NULL ))AND(([[Barcode] = @original_Barcode)OR([[Barcode] IS NULL AND @original_Barcode IS NULL))& gt; < 删除参数 > < asp:parameters 名称 =" 类型 Int16 " / < asp:parameters 名称 =" 类型 字符串" / < asp:parameters 名称 =" 类型 字符串" / < /deleteparameters > < 插入参数 > < asp:parameters 名称 =" 类型 Int16 " / < asp:parameters 名称 =" 类型 字符串" / < asp:parameters 名称 =" 类型 字符串" / < /insertparameters > < updateparameters > < asp:parameters 名称 =" 类型 字符串" / < asp:parameters 名称 =" 类型 字符串" / < asp:parameters 名称 =" 类型 Int16 " / < asp:parameters 名称 =" 类型 字符串" / < asp:parameters 名称 =" 类型 字符串" / < /updateparameters > < /asp:sqldatasource > < /td > < /tr > < /table > < /div > < /form > < /body > < /html >
ConnectionStrings:TestDbaConnectionString %&gt;" DeleteCommand="DELETE FROM [TestChecklist] WHERE [No] = @original_No AND (([Item] = @original_Item) OR ([Item] IS NULL AND @original_Item IS NULL)) AND (([Barcode] = @original_Barcode) OR ([Barcode] IS NULL AND @original_Barcode IS NULL))" InsertCommand="INSERT INTO [TestChecklist] ([No], [Item], [Barcode]) VALUES (@No, @Item, @Barcode)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [No], [Item], [Barcode] FROM [TestChecklist]" UpdateCommand="UPDATE [TestChecklist] SET [Item] = @Item, [Barcode] = @Barcode WHERE [No] = @original_No AND (([Item] = @original_Item) OR ([Item] IS NULL AND @original_Item IS NULL)) AND (([Barcode] = @original_Barcode) OR ([Barcode] IS NULL AND @original_Barcode IS NULL))"&gt; <deleteparameters> <asp:parameter name="original_No" type="Int16" /> <asp:parameter name="original_Item" type="String" /> <asp:parameter name="original_Barcode" type="String" /> </deleteparameters> <insertparameters> <asp:parameter name="No" type="Int16" /> <asp:parameter name="Item" type="String" /> <asp:parameter name="Barcode" type="String" /> </insertparameters> <updateparameters> <asp:parameter name="Item" type="String" /> <asp:parameter name="Barcode" type="String" /> <asp:parameter name="original_No" type="Int16" /> <asp:parameter name="original_Item" type="String" /> <asp:parameter name="original_Barcode" type="String" /> </updateparameters> </asp:sqldatasource> </td> </tr> </table> </div> </form> </body> </html>



[修改:添加了前置标记]



[Modified: added pre tags]


这似乎是一项复杂的初学者任务.您还应该知道,任何人付费或使用的代码都不能使用这种在aspx中定义了SQL的代码.这实际上仅适用于正在玩耍且未获得报酬的初学者.既然如此,您现在就可以了,很高兴知道.

据我所知,一旦控件具有数据源,就不能只向其中插入值.您可以使用模板来插入文本框,当文本框被更改时,您可以更新数据源以反映这些更改,或者可以使UI显示方式取决于这些更改,但是任何数据更改都应在数据层中完成. .
This seems like a complex beginner task. You should also know, no code that anyone pays for or uses should ever use this sort of code, where SQL is defined in the aspx. That''s really only for beginners who are playing around and not being paid. As that''s what you are, that''s fine for now, it''s just good to know.

As far as I am aware, once your control has a data source, you can''t just insert values into it. You CAN use a template to insert textboxes and when those are changed, you can update your data source to reflect those changes, or you can make the way your UI displays dependant on those changes, but any data changes should be done in the data layer.


这篇关于有人知道如何在Gridview中修改值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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