无法得到我的主人和详细gridview工作

时间:2010-03-06 01:27:09

标签: c# asp.net sql

我无法让这个工作。我是编程方面的新手,对此感到非常感激。

<%@ Page Language="C#" %>
<!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 Page_Load(object sender, EventArgs e)
{

}

protected void DataGridSqlDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{

}
</script>

 <html xmlns="http://www.w3.org/1999/xhtml">
 <head runat="server">
<title>Untitled Page</title>
 </head>
 <body>
<form id="form1" runat="server">
<div>
 <asp:SqlDataSource ID="DataGrid2SqlDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:JobPostings1ConnectionString %>"             
        SelectCommand="SELECT [Jobs_PK], [Position_Title], [Educ_Level], [Grade],    [JP_Description], [Job_Status], [Position_ID] FROM [Jobs]" 
        FilterExpression="Jobs_PK='@Jobs_PK'">          
         <filterparameters>
            <asp:ControlParameter Name="Jobs_PK" 
                ControlId="GridView1" PropertyName="SelectedValue" />
        </filterparameters>            
       </asp:SqlDataSource>                   
    <asp:SqlDataSource ID="DataGridSqlDataSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:JobPostings1ConnectionString %>" 
        SelectCommand="SELECT [Position_Title], [Jobs_PK] FROM [Jobs]" 
        onselecting="DataGridSqlDataSource_Selecting">
    </asp:SqlDataSource>
    <asp:GridView ID="GridView1" runat="server" 
        AutoGenerateColumns="False" DataKeyNames="Jobs_PK" 
        DataSourceID="DataGridSqlDataSource" AllowPaging="True" 
        AutoGenerateSelectButton="True" SelectedIndex="0" Width="100px">
        <Columns>
            <asp:BoundField DataField="Position_Title" HeaderText="Position_Title" 
                SortExpression="Position_Title" />
            <asp:BoundField DataField="Jobs_PK" HeaderText="Jobs_PK"      InsertVisible="False" 
                ReadOnly="True" SortExpression="Jobs_PK" />
        </Columns>
    </asp:GridView>
    <br />
    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
        DataKeyNames="Jobs_PK" DataSourceID="DataGrid2SqlDataSource" Height="50px" 
        Width="125px">
        <Fields>
            <asp:BoundField DataField="Jobs_PK" HeaderText="Jobs_PK" InsertVisible="False" 
                ReadOnly="True" SortExpression="Jobs_PK" />
            <asp:BoundField DataField="Position_Title" HeaderText="Position_Title" 
                SortExpression="Position_Title" />
            <asp:BoundField DataField="Educ_Level" HeaderText="Educ_Level" 
                SortExpression="Educ_Level" />
            <asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
            <asp:BoundField DataField="JP_Description" HeaderText="JP_Description" 
                SortExpression="JP_Description" />
            <asp:BoundField DataField="Job_Status" HeaderText="Job_Status" 
                SortExpression="Job_Status" />
            <asp:BoundField DataField="Position_ID" HeaderText="Position_ID" 
                SortExpression="Position_ID" />
        </Fields>
    </asp:DetailsView>
 </div>
 </form>
 </body>

错误讯息: 无法对System.Int32和System.String执行'='操作。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Data.EvaluateException:无法对System.Int32和System.String执行'='操作。

2 个答案:

答案 0 :(得分:1)

在你的asp:ControlParameter上添加type =“Int32”属性。 E.g:

<asp:ControlParameter Name="Jobs_PK" type="Int32" 
                ControlId="GridView1" PropertyName="SelectedValue" />

答案 1 :(得分:0)

删除@Jobs_PK周围的单引号,这样:

FilterExpression="Jobs_PK='@Jobs_PK'">  

应该是:

FilterExpression="Jobs_PK=@Jobs_PK">