开发者

Unable to get my master & details gridview to work

I'm unable to get this to work. I'm very new at programming and would appreciate any help on this.

<%@ 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>

error message: Cannot perform '=' operation on System.Int32 and System.String. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.EvaluateException: Cannot perform '=' operation on System.Int32 and System.String.


On your asp:ControlParameter add type="Int32" attribute. E.g.:

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


Remove the single quotes around the @Jobs_PK so this:

FilterExpression="Jobs_PK='@Jobs_PK'">  

should be:

FilterExpression="Jobs_PK=@Jobs_PK">  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜