回 帖 发 新 帖 刷新版面

主题:[讨论]数据绑定错误,请大家指导

<%@ Page Language="C#" debug="true"%>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient" %>


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

<script runat="server">

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString2 %>"
            SelectCommand="SELECT * FROM [People]" UpdateCommand="UPDATE [People] SET LastName = @LastName, FirstName = @FirstName  WHERE pkID =@pkID" DeleteCommand="delete from [People] WHERE pkID=@pkID">
           

            </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" Height="100%" Width="100%">
            <Columns>
                <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName"  />
                <asp:BoundField DataField="pkID" HeaderText="pkID" InsertVisible="False" SortExpression="pkID" />
                <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True">
                    <ControlStyle BackColor="#FFC0FF" />
                </asp:CommandField>
                
            </Columns>
          
            <FooterStyle BackColor="Tan" />
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
            
        </asp:GridView>
        &nbsp;&nbsp;</div>
    </form>
</body>
</html>



大家帮我看一下,运行后老出现这个错误:@pcID没有定义

回复列表 (共1个回复)

沙发

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:apipcmsConnectionString %>"
                    SelectCommand="SELECT * FROM [BOM] WHERE ([DESC] = @DESC)">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="cvContactTime" DefaultValue="0" Name="DESC" PropertyName="Text"
                            Type="String" />
                    </SelectParameters>
                </asp:SqlDataSource>
你没有指定参数的值呀.
@pkID相当于一个变量名,你要赋值呀.

我来回复

您尚未登录,请登录后再回复。点此登录或注册