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="AlternatingRowSt
yle_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")%></as
p:HyperLin
k>
</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.eva
l(containe
r, "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].HeaderT
ext = "Request #";
dgTasks.Columns[0].HeaderT
ext = "Priority";
dgTasks.Columns[0].HeaderT
ext = "Stage";
dgTasks.Columns[0].HeaderT
ext = "Create Date";
dgTasks.Columns[0].HeaderT
ext = "Application Name";
dgTasks.Columns[0].HeaderT
ext = "Status";
dgTasks.Columns[0].HeaderT
ext = "Assigned";
// DataTable Columns
dt.Columns.Add("Request #", Type.GetType("System.Strin
g"));
dt.Columns.Add("Priority",
Type.GetType("System.Strin
g"));
dt.Columns.Add("Stage", Type.GetType("System.Strin
g"));
dt.Columns.Add("Create Date", Type.GetType("System.Strin
g"));
dt.Columns.Add("Applicatio
n Name", Type.GetType("System.Strin
g"));
dt.Columns.Add("Requested For", Type.GetType("System.Strin
g"));
dt.Columns.Add("Status", Type.GetType("System.Strin
g"));
dt.Columns.Add("Assigned",
Type.GetType("System.Strin
g"));
// 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