asp.net - How to bind the URL of a GridView HyperLinkField when the bound value contains a colon? -
i'm trying bind gridview hyperlinkfield such bound column used parameter value in url. pretty standard stuff - nothing fancy, binding fails when bound column contains colon, i.e. :
. i'm particular case, value string representing duration of time, e.g. "14:35", or "1:07:19".
here's gridview, time value bound hyperlinkfield url.
<asp:gridview id="resultsgridview" runat="server" autogeneratecolumns="false" datasourceid="resultsdatasource" enablemodelvalidation="true" allowpaging="true"> <columns> <asp:boundfield datafield="year" headertext="year" sortexpression="year" /> <asp:hyperlinkfield datanavigateurlfields="runtime" datatextfield="runtime" headertext="hyperlink" datanavigateurlformatstring="linkedpage.aspx?param={0}" /> <asp:boundfield datafield="runtime" headertext="time" sortexpression="runtime" /> <asp:boundfield datafield="fullname" headertext="name" sortexpression="fullname" readonly="true" /> </columns> </asp:gridview>
it produces html this. note <a>
tags have no href
attribute.
<tr> <td>2010</td><td><a>34:58</a></td><td>34:58</td><td>joe schmoe</td> </tr><tr> <td>2010</td><td><a>35:30</a></td><td>35:30</td><td>rod krueger</td> </tr><tr> <td>2010</td><td><a>35:38</a></td><td>35:38</td><td>mike johnson</td> </tr>
but if switch bound field runtime year, i.e. column doesn't contain colon in values, works expected. take gridview above, , change datanavigateurlfields attribute of hyperlinkfield, so:
<asp:hyperlinkfield datanavigateurlfields="year" datatextfield="runtime" headertext="hyperlink" datanavigateurlformatstring="linkedpage.aspx?param={0}" />
and html output correct, this:
<tr> <td>2010</td><td><a href="linkedpage.aspx?param=2010">34:58</a></td><td>34:58</td><td>joe schmoe</td> </tr><tr> <td>2010</td><td><a href="linkedpage.aspx?param=2010">35:30</a></td><td>35:30</td><td>rod krueger</td> </tr><tr> <td>2010</td><td><a href="linkedpage.aspx?param=2010">35:38</a></td><td>35:38</td><td>mike johnson</td> </tr><tr>
so nut of question this: how bind data column values contain colon url of hyperlinkfield? or, failing that, create same bound hyperlink method?
changing format of data not include colon last resort, because linkedpage.aspx expects parameter value in format, , it's written, tested , in use.
<asp:templatefield headertext="hyperlink"> <itemtemplate> <asp:hyperlink id="hyperlink1" runat="server" navigateurl='<%# eval("runtime", @"linkedpage.aspx?param={0:hh\:mm}") %>' text='<%# eval("runtime", @"{0:hh\:mm}") %>'></asp:hyperlink> </itemtemplate> </asp:templatefield>
Comments
Post a Comment