当前位置:编程学习 > C#/ASP.NET >>

GridView中遇到的问题(无法更新)???

GridView中更新时难道必须自己添加代码?
我的是:
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Height="106px" Text="Label" Width="436px"></asp:Label>
           <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" Width="630px">
            <Columns>
                <asp:TemplateField HeaderText="类型" SortExpression="Customer_type">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Customer_type") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Customer_type") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="客户ID" SortExpression="Customer_ID">
                    <EditItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Customer_ID") %>'></asp:Label>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("Customer_ID") %>' Width="66px"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="单位名称" SortExpression="Customer_name">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Customer_name") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Customer_name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="联系电话" SortExpression="Customer_tel">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Customer_tel") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("Customer_tel") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="公司地址" SortExpression="Customer_address">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Customer_address") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label5" runat="server" Text='<%# Bind("Customer_address") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField HeaderText="删除" ShowDeleteButton="True" ShowHeader="True" />
                <asp:CommandField HeaderText="修改" ShowEditButton="True" ShowHeader="True" />
            </Columns>
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <EditRowStyle BackColor="#999999" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
         
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DatabaseConnection %>"
            SelectCommand="SELECT [Customer_ID], [Customer_name], [Customer_tel], [Customer_address], [Customer_type] FROM [Customer]" ConflictDetection="CompareAllValues" DeleteCommand="DELETE FROM [Customer] WHERE [Customer_ID] = @original_Customer_ID AND [Customer_name] = @original_Customer_name AND [Customer_tel] = @original_Customer_tel AND [Customer_address] = @original_Customer_address AND [Customer_type] = @original_Customer_type" InsertCommand="INSERT INTO [Customer] ([Customer_ID], [Customer_name], [Customer_tel], [Customer_address], [Customer_type]) VALUES (@Customer_ID, @Customer_name, @Customer_tel, @Customer_address, @Customer_type)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Customer] SET [Customer_name] = @Customer_name, [Customer_tel] = @Customer_tel, [Customer_address] = @Customer_address, [Customer_type] = @Customer_type WHERE [Customer_ID] = @original_Customer_ID AND [Customer_name] = @original_Customer_name AND [Customer_tel] = @original_Customer_tel AND [Customer_address] = @original_Customer_address AND [Customer_type] = @original_Customer_type">
            <DeleteParameters>
                <asp:Parameter Name="original_Customer_ID" Type="String" />
                <asp:Parameter Name="original_Customer_name" Type="String" />
                <asp:Parameter Name="original_Customer_tel" Type="String" />
                <asp:Parameter Name="original_Customer_address" Type="String" />
                <asp:Parameter Name="original_Customer_type" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Customer_name" Type="String" />
                <asp:Parameter Name="Customer_tel" Type="String" />
                <asp:Parameter Name="Customer_address" Type="String" />
                <asp:Parameter Name="Customer_type" Type="String" />
                <asp:Parameter Name="original_Customer_ID" Type="String" />
                <asp:Parameter Name="original_Customer_name" Type="String" />
                <asp:Parameter Name="original_Customer_tel" Type="String" />
                <asp:Parameter Name="original_Customer_address" Type="String" />
                <asp:Parameter Name="original_Customer_type" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Customer_ID" Type="String" />
                <asp:Parameter Name="Customer_name" Type="String" />
                <asp:Parameter Name="Customer_tel" Type="String" />
                <asp:Parameter Name="Customer_address" Type="String" />
                <asp:Parameter Name="Customer_type" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>
           </div>
    </form>
</body>
</html>
但却无法完成更新(点击更新时,字段无变化)是什么原因??? --------------------编程问答-------------------- 自己先顶个
没人回答吗???
急急急急急急急急急急急急急急急急急急急急急急急急急急急急急 --------------------编程问答-------------------- 我认为是因为你把每列都换成了模板列的缘故.把自己搞麻烦了,结果反而出问题.

你不用换成模板列,可以直接改列标题,再把DataField属性写成你要帮的字段就行了. --------------------编程问答-------------------- 1。
GridView中更新时难道必须自己添加代码?
-----------
你直接使用 xxxDataSource 是不需要自己另外写代码的

2。
xxxDataSource 问题,我无法解释了,基本没用过 :D
按理,对于 xxxDataSource 来说,不应该存在 IsPostBack 的问题 --------------------编程问答-------------------- 3。
哦, 看到问题所在了, 好像是因为你没有指定主键 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" Width="630px">

》》》 加上 DataKeyNames,这里假设你的主键是  Customer_ID


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None" Width="630px" DataKeyNames="Customer_ID"> --------------------编程问答-------------------- 更新之后要重新以下绑定一下DataView才行 --------------------编程问答-------------------- 还是建议不要用这个功能吧。 呵呵呵呵 --------------------编程问答-------------------- 更新后,要重新刷新下GridView,这样的话,你的数据就是比较新的数据.我经常使用这个.
不明白可以联系:MSN:wzhh598@hotmail.com --------------------编程问答-------------------- 是主键问题。 --------------------编程问答-------------------- 修改数据以后,刷新一下dataview --------------------编程问答-------------------- 让人很不解的是
怎么会有两个id= label1
一定有问题  --------------------编程问答-------------------- 路过··· --------------------编程问答-------------------- 更新后要重新绑定一下....
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,