开发者

Retrieving two SQL queries from one page to other using hyperlink GridView

I have a code to pass the query from a one page that has a gridview hyperlink but what I didn't know is how to retrieve it..

Here is my code I hope you could help me fix this one.. thnx

Have a nice day ^^,

Default1.aspx (Gridview1) page:

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" HorizontalAlign="Center" Width="570px" 
            AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None">
        <RowStyle BackColor="#E3EAEB" />
        <Columns>
            <asp:BoundField DataField="course_cat" HeaderText="course_cat" SortExpression="course_cat" />
            <asp:BoundField DataField="section_name" HeaderText="section_name" SortExpression="section_name" />               
            <asp:BoundField DataField="no_of_students" HeaderText="numberofstudents" SortExpression="no_of_students" />                
            <asp:BoundField DataField="section_id" HeaderText="section_id" InsertVisible="False" ReadOnly="True" SortExpression="section_id" Visible="False" />
            <asp:BoundField DataField="course_id" HeaderText="course_id" InsertVisible="False" ReadOnly="True" SortExpression="course_id" Visible="False" />
            <asp:HyperLinkField DataNavigateUrlFields="section_id,course_id" DataNavigateUrlFormatString="ClassList.aspx?section_id={0}& course_id={1}" Text="View Students" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:dbProLearnConnectionString %>" 
        SelectCommand="SELECT tblCourses.course_id, tblCourses.course_cat, tblSections.section_id, tblSections.section_name, tblSections.no_of_students FROM tblCourses 
        CROSS JOIN tblSections GROUP BY tblCourses.course_id, tblCourses.course_cat, tblSections.section_id, tblSections.section_name, tblSections.no_of_students">
    </asp:SqlDataSource>

Default2.aspx(Gridview2) Page:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" HorizontalAlign="Center" Width="570px" 
            AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None">
        <RowStyle BackColor="#E3EAEB" />
        <Columns>
            <asp:BoundField DataField="StudentID" HeaderText="StudentID" SortExpression="StudentID" />
            <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName"  SortExpression="FirstName" />
            <asp:TemplateField HeaderText="section_name" SortExpression="section_name">
                <EditItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("section_name") %>' />
                </EditItemTemplate>
                <ItemTemplate>
                    开发者_JAVA百科<asp:Label ID="Label1" runat="server" Text='<%# Eval("section_name") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="course_cat" SortExpression="course_cat">
                <EditItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("course_cat") %>' />
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("course_cat") %>' />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:dbProLearnConnectionString %>" 
    OldValuesParameterFormatString="original_{0}" 
    SelectCommand="SELECT tblStudents.StudentID, tblStudents.LastName, tblStudents.FirstName, (SELECT section_name FROM tblSections AS tblSections_1 
    WHERE (tblStudentSubject.section_id = section_id)) AS section_name, (SELECT course_cat FROM tblCourses AS tblCourses_1 
    WHERE (tblStudentSubject.course_id = course_id)) AS course_cat FROM tblStudentSubject 
    INNER JOIN tblStudents ON tblStudentSubject.student_id = tblStudents.StudentID 
    INNER JOIN tblCourses AS tblCourses ON tblStudentSubject.course_id = tblCourses.course_id 
    INNER JOIN tblSections AS tblSections ON tblStudentSubject.section_id = tblSections.section_id 
    WHERE (tblStudentSubject.section_id = @section_id) AND (tblStudentSubject.course_id = @course_id) ORDER BY tblStudents.LastName">       
    <SelectParameters>
        <asp:QueryStringParameter Name="section_id" QueryStringField="section_id" />
        <asp:QueryStringParameter Name="course_id" QueryStringField="course_id" />
    </SelectParameters>
</asp:SqlDataSource>


Not sure what exactly is the issue that your are facing - only thing that amiss in your code is type for QueryStringParameter.

<asp:QueryStringParameter Name="section_id" type="string" QueryStringField="section_id" />


Thanks for your response and time VinayC.. i finally figured it out on my own.. with the tip on your answer... thanks again ^^,

Here's The Formal code

SubjectClass.aspx w/c i named as (Default1.aspx(Gridview1)) in my sample

       <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" HorizontalAlign="Center" Width="570px" 
            AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None">
        <RowStyle BackColor="#E3EAEB" />
        <Columns>
            <asp:BoundField DataField="course_cat" HeaderText="Course Catalog" 
                SortExpression="course_cat">
            </asp:BoundField>
            <asp:BoundField DataField="section_name" HeaderText="Section Name" 
                SortExpression="section_name">
            </asp:BoundField>

             <asp:BoundField DataField="no_of_students" HeaderText="No. Of Students" 
                SortExpression="no_of_students">
            </asp:BoundField>

            <asp:BoundField DataField="section_id" HeaderText="section_id" 
                InsertVisible="False" ReadOnly="True" SortExpression="section_id" Visible="False" />
            <asp:BoundField DataField="course_id" HeaderText="course_id" 
                InsertVisible="False" ReadOnly="True" SortExpression="course_id" Visible="False" />

            <asp:HyperLinkField DataNavigateUrlFormatString="ClassList.aspx?section_id={0}&course_id={1}" 
                DataNavigateUrlFields="section_id,course_id" Text="View Students"/>

        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:dbProLearnConnectionString %>" 
        SelectCommand="SELECT tblStudentSubject.course_id, tblStudentSubject.section_id, tblCourses.course_cat, tblSections.section_name, tblSections.no_of_students FROM tblStudentSubject 
        INNER JOIN tblCourses ON tblStudentSubject.course_id = tblCourses.course_id 
        INNER JOIN tblSections ON tblStudentSubject.section_id = tblSections.section_id 
        GROUP BY tblStudentSubject.course_id, tblStudentSubject.section_id, tblCourses.course_cat, tblSections.section_name, tblSections.no_of_students">
    </asp:SqlDataSource>

ClassList.aspx w/c i named as (Default2.aspx(Gridview2)) in my sample

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataSourceID="SqlDataSource1" HorizontalAlign="Center" Width="570px" 
            AllowPaging="True" CellPadding="4" ForeColor="#333333" 
    GridLines="None">
        <RowStyle BackColor="#E3EAEB" />
        <Columns>
            <asp:BoundField DataField="LastName" HeaderText="LastName" 
                SortExpression="LastName" />
            <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                SortExpression="FirstName" />
            <asp:BoundField DataField="section_name" HeaderText="section_name" 
                SortExpression="section_name" />
            <asp:BoundField DataField="course_cat" HeaderText="course_cat" 
                SortExpression="course_cat" />
            <asp:BoundField DataField="section_id" HeaderText="section_id" 
                SortExpression="section_id" Visible="False" />
            <asp:BoundField DataField="course_id" HeaderText="course_id" 
                SortExpression="course_id" Visible="False" />
        </Columns>
    </asp:GridView>

   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:dbProLearnConnectionString %>"   
    SelectCommand="SELECT tblStudents.LastName, tblStudents.FirstName, tblSections.section_name, tblCourses.course_cat, tblStudentSubject.section_id, tblStudentSubject.course_id FROM tblStudentSubject INNER JOIN tblStudents ON tblStudentSubject.student_id = tblStudents.StudentID INNER JOIN tblSections ON tblStudentSubject.section_id = tblSections.section_id INNER JOIN tblCourses ON tblStudentSubject.course_id = tblCourses.course_id WHERE (tblStudentSubject.section_id = @section_id) AND (tblStudentSubject.course_id = @course_id)">
    <SelectParameters>
        <asp:QueryStringParameter Name="section_id" QueryStringField="section_id" 
            Type="Int32" />
        <asp:QueryStringParameter Name="course_id" QueryStringField="course_id" 
            Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜