Advertisement

09.02.2008 at 11:34AM PDT, ID: 23696933
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

How to add a hyperlink programmatically to column in DataTable in order to Bind to DataGrid

Asked by dba123 in Programming for ASP.NET

I'm trying to figure out how I can add a hyperlink to the "assign" column of my DataTable so that when I bind to my DataGrid, it shows that hyperlink.  Please loko at both my DataGrid's assign column synt and the assign clumn and row syntax as I acnnot figure out the syntax on how to add a hyperlink to the assign column programatically.

Here's my DataGrid:

                                                <asp:DataGrid ID="dgTasks" runat="server" allowpaging="True"
                                                    allowsorting="True" autogeneratecolumns="False" pagerstyle-visible="false"
                                                    width="100%">
                                                    <selecteditemstyle cssclass="rowdetailactive" />
                                                    <alternatingitemstyle borderstyle="none"
                                                        cssclass="AlternatingRowStyle_middle" />
                                                    <itemstyle cssclass="rowdetail" />
                                                    <headerstyle cssclass="repeater_header" />
                                                    <columns>
                                                        <asp:templatecolumn sortexpression="2">
                                                            <headerstyle width="100px" wrap="false" />
                                                            <itemtemplate>
                                                                <asp:HyperLink ID="hplPriority" runat="server"><%# databinder.eval(container, "dataitem.Priority")%></asp:HyperLink>
                                                            </itemtemplate>
                                                        </asp:templatecolumn>
                                                        <asp:templatecolumn sortexpression="3">
                                                            <headerstyle width="90px" wrap="false" />
                                                            <itemtemplate>
                                                                <%# databinder.eval(container, "dataitem.Task")%>
                                                            </itemtemplate>
                                                        </asp:templatecolumn>
                                                        <asp:templatecolumn sortexpression="4">
                                                            <headerstyle width="90px" wrap="false" />
                                                            <itemtemplate>
                                                                <%# databinder.eval(container, "dataitem.CreateDate")%>
                                                            </itemtemplate>
                                                        </asp:templatecolumn>
                                                        <asp:templatecolumn sortexpression="5">
                                                            <headerstyle width="90px" wrap="false" />
                                                            <itemtemplate>
                                                                <%# displaydate(databinder.eval(container, "dataitem.ApplicationName"))%>
                                                            </itemtemplate>
                                                        </asp:templatecolumn>
                                                        <asp:templatecolumn sortexpression="6">
                                                            <headerstyle width="140px" wrap="false" />
                                                            <itemtemplate>
                                                                <%# databinder.eval(container, "dataitem.RequestedFor")%>
                                                            </itemtemplate>
                                                        </asp:templatecolumn>
                                                        <asp:templatecolumn sortexpression="7">
                                                            <headerstyle width="180px" wrap="false" />
                                                            <itemtemplate>
                                                                <%# databinder.eval(container, "dataitem.Status")%>
                                                            </itemtemplate>
                                                        </asp:templatecolumn>
                                                        <asp:templatecolumn>
                                                            <headerstyle width="90px" wrap="false" />
                                                            <itemtemplate>
                                                                <%# databinder.eval(container, "dataitem.Assigned")%>
                                                            </itemtemplate>
                                                        </asp:templatecolumn>
                                                    </columns>
                                                    <pagerstyle visible="false" />
                                                </asp:DataGrid>

Here's where I am trying to specify a hyperlink for my DataTable row cell for "assign"

            DataTable dt = new DataTable();

            // Create DataGrid Header
            dgTasks.Columns[0].HeaderText = "Request #";
            dgTasks.Columns[0].HeaderText = "Priority";
            dgTasks.Columns[0].HeaderText = "Stage";
            dgTasks.Columns[0].HeaderText = "Create Date";
            dgTasks.Columns[0].HeaderText = "Application Name";
            dgTasks.Columns[0].HeaderText = "Status";
            dgTasks.Columns[0].HeaderText = "Assigned";

            // DataTable Columns
            dt.Columns.Add("Request #", Type.GetType("System.String"));
            dt.Columns.Add("Priority", Type.GetType("System.String"));
            dt.Columns.Add("Stage", Type.GetType("System.String"));
            dt.Columns.Add("Create Date", Type.GetType("System.String"));
            dt.Columns.Add("Application Name", Type.GetType("System.String"));
            dt.Columns.Add("Requested For", Type.GetType("System.String"));
            dt.Columns.Add("Status", Type.GetType("System.String"));
            dt.Columns.Add("Assigned", Type.GetType("System.String"));

            // Create Rows in the Grid now
            DataRow dr = dt.NewRow();
            dr["Request #"] = "1123";
            dr["Priority"] = "High";
            dr["Stage"] = "Approval Stage";
            dr["Create Date"] = "04/12/2008";
            dr["Application Name"] = sxxxxt";
            dr["Requested For"] = "xxxh";
            dr["Status"] = "Pending";
            dr["Assigned"] = "<need hyperlink here>" ;

Keep in mind this is just for adding some dummy hard coded hyperlinks to each row of my DataTable since I'm diong this for demonstration purposes, this is not going to be tied to any datasource.  I want to eventually add 2-3 more rows to the DataTable and hard code in a different hyperlink every time from code-behind.

I'm thinking something like this might work:

dr["Assigned"] = "<input type=""checkbox"" id=""assign"" href=""../somepage.aspx"">";
Start Free Trial
 
Loading Advertisement...
 
[+][-]09.02.2008 at 12:04PM PDT, ID: 22370386

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Programming for ASP.NET
Sign Up Now!
Solution Provided By: Chirag1211
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628