views:

38

answers:

2

Greetings everyone,

I have a code to pass the querry 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>
                    <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>
A: 

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" />
VinayC
Thanks for the response VinayC,My problem is i have my Default1.aspx and a hyperlink data in gridview1 which is named as View Student ...when i clicked it.. i am expecting that it will pass the section_id and course_id data into Default2.aspx that needs the section_id and course_id data to filter the gridview2.. but my gridview2 doesn't appear..that's my problem..
Kid
I have used "ClassList.aspx" in your hyperlink instead of default2.aspx. But assuming that just for asking question, when you click on link, does query parameters get passed correctly? I mean do you see those correct values in url? If yes then check if query for those parameters return zero rows or not. If there are zero rows you won't see anything unless you provide EmptyDataTemplate or EmptyDataText.
VinayC
i'd like to give you +1 but it says i don't have enough reputation ^^, thanks again
Kid
A: 

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>
Kid