Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi people

Need an advice to create a dynamic c# ASP.Net gridview that will have different NavigateURL attribute in my column. E.g


Now the courseName must be a hyperlinkfield and the links must be different for each courseName

Sounds like homework. I certainly hope it's not paid work. I don't know what you mean by dynamic, but it sounds like you just want to create a template for your gridview that generates a URL from the data you're binding to. This is the first thing that any book or online example would teach you. Do you own any books ? Does your school ? Does google work where you live ?
Share this answer
Haha... yes google worx where i live. This is what I have done in my gridview and its not working.

                <asp:HyperLinkField DataTextField="courseName" HeaderText="Course Tittle"
                    <HeaderStyle ForeColor="White" />
                <asp:BoundField DataField="courseCode" HeaderText="Course Code" ReadOnly="True"
                    SortExpression="courseCode" >
                    <HeaderStyle ForeColor="White" />
                <asp:BoundField DataField="coursePrice" HeaderText="Course Price"
                    SortExpression="coursePrice" >
                    <HeaderStyle ForeColor="White" />

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
           ConnectionString="<%$ ConnectionStrings:scheduleConnectionString %>"
           ProviderName="<%$ ConnectionStrings:scheduleConnectionString.ProviderName %>"
           SelectCommand="SELECT [courseName], [courseCode], [coursePrice] FROM [courses] ORDER BY [courseName]">
Share this answer
Christian Graus 10-Aug-10 15:48pm    
Some pointers if you want to find help here.

1 - don't push 'answer' to 'comment'. Just like I did not push 'comment' to 'answer'
2 - Don't tell us it's 'not working'. Tell us what you expect it to do, what it does, and where you're stuck. This code works. It does what you asked it to do. You've done nothing to build a URL that differs in any way here, so what do you expect it to do ?
Anele Ngqandu 10-Aug-10 16:05pm    
Okey...The DataTextField "courseName" in my gridView must have or generate different URL for each course name that is seen in the grid...The code that I have generates the same URL for different courses. Hope thats more clear.
Christian Graus 10-Aug-10 16:23pm    
So, do you own any books ? Have you done any research ? You can specify your URL in the Hyperlinkfield so that it's built using the courseCode, etc, and build a URL that has a query string that is used to identify the required course.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900