Hi everyone. I have a form which has a drop down list bound to my database. When i select an item from the dropdown list, it redirects me to another page register.aspx with a query string containing the value of the course_id. The problem is that i want to use the id in the query string to fetch the course name and display it in a textbox.

<asp:DropDownList ID="dropSelectField" 
runat="server" 
AutoPostBack="True"
 DataSourceID="srcFields" 
DataTextField="Field_name" 
DataValueField="Field_ID"
 EnableViewState="False">
</asp:DropDownList>

     
    <asp:ObjectDataSource ID="srcCourses" 
    Typename = "FilterFields"
    SelectMethod ="GetCourses"
    EnableCaching = "true"
    Cacheduration = "infinite" 
    FilterExpression = "Field_ID={0}"
    runat="server">
    <FilterParameters >
    <asp:ControlParameter Name = "Field_name"
     ControlID = "dropSelectfield" />
              
    </FilterParameters>
    
    </asp:ObjectDataSource>
    <asp:ObjectDataSource ID="srcFields" 
     TypeName ="FilterFields"
     SelectMethod ="GetFields"
      EnableCaching = "true"
      Cacheduration = "infinite" 
    runat="server">
    </asp:ObjectDataSource>
   
     
    <asp:GridView ID="grdCourses" 
runat="server" AutoGenerateColumns="False" 
DataSourceID="srcCourses"
EnableViewState="False" >
        
        <Columns >
        <asp:BoundField  DataField ="Course_ID" HeaderText = "Course_ID"/>
        
         <asp:HyperLinkField HeaderText ="Click on link to register"
        DataTextField="Course_name"
        DataNavigateUrlFields="Course_ID"
        DataNavigateUrlFormatString="RegisterStudent.aspx?courseid={0}" />
      
        
       
        </Columns>
        
                    
    </asp:GridView>

Recommended Answers

All 2 Replies

in the page load event we should read the query string to retrieve the courseid like

int CourseID = Convert.ToInt32(Request.QueryString["sid"].ToString());

I'am assuming that the course id in the database is of integer data type. pass this CourseID as a parameter to the course name select query.

Thanks! That solved my problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.