By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,518 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Hyperlinks on a Grid

P: 3
I'm trying to get hyperlinks to edit my table entries and it is not working.
MakeDataTable(dtSelDate) does the bulk of the work populating the data table _dt which contains all the event information. I don't add anything for the hyperlinks, assuming it would come from the datatable columns. See below for output.

Help!


BoundField colID = new BoundField();
//colID.DataField = "EventID";
colID.DataField = "ID";
colID.DataFormatString = "{0}";
colID.HeaderText = "ID";
colID.Visible = false ;

BoundField colDay = new BoundField();
colDay.DataField = "Day";
colDay.DataFormatString = "{0}";
colDay.HeaderText = "Day";
colDay.Visible = false;

BoundField colTime = new BoundField();
colTime.DataField = "Time";
colTime.DataFormatString = "{0}";
colTime.HeaderText = "Time";

BoundField colEvent = new BoundField();
colEvent.DataField = "Event";
colEvent.DataFormatString = "{0}";
colEvent.HeaderText = "Event";

HyperLinkField colEdit = new HyperLinkField();
colEdit.DataTextField = "Edit";
colEdit.DataTextFormatString = "{0} ";
colEdit.DataNavigateUrlFields = new string[] { "Day", "ID" };
colEdit.DataNavigateUrlFormatString = "AddEvent.aspx?daysel={0}&id={1}";
colEdit.HeaderText = "Edit";

HyperLinkField colDel = new HyperLinkField();
colDel.DataTextField = "Delete";
colDel.DataTextFormatString = "{0}";
colDel.DataNavigateUrlFields = new string[] { "Day","ID" };
colDel.DataNavigateUrlFormatString = "AddEvent.aspx?daysel={0}&id={1}";
colDel.HeaderText = "Delete";

gvDay.Columns.Add(colID);
gvDay.Columns.Add(colDay);
gvDay.Columns.Add(colTime);
gvDay.Columns.Add(colEvent);
gvDay.Columns.Add(colEdit);
gvDay.Columns.Add(colDel);
gvDay.AutoGenerateColumns = false;
gvDay.DataKeyNames = new string[] { "ID" };

MakeDataTable(dtSelDate);

gvDay.DataSource = _dt;
gvDay.Width = Unit.Pixel(700);
gvDay.GridLines = 0;
gvDay.CssClass = "h2";
gvDay.HeaderStyle.CssClass = "h2";
gvDay.DataBind();


Here is what it generates:

<table class="h2" cellspacing="0" border="0" id="gvDay" style="width:700px;border-collapse:collapse;">
<tr class="h2">
<th scope="col">Time</th><th scope="col">Event</th><th scope="col">Edit</th><th scope="col">Delete</th>
</tr><tr>
<td>06:00 AM</td><td>[6:00 AM to 12:00 AM Run Outside ]</td><td><a></a></td><td><a></a></td>
</tr><tr class="altRow">
<td>07:00 AM</td><td>[7:00 AM to 12:00 AM Leap Frog Front Yard]</td><td><a></a></td><td><a></a></td>
</tr><tr>
<td>08:00 AM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr class="altRow">
<td>09:00 AM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr>
<td>10:00 AM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr class="altRow">
<td>11:00 AM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr>
<td>12:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr class="altRow">
<td>01:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr>
<td>02:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr class="altRow">
<td>03:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr>
<td>04:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr class="altRow">
<td>05:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr>
<td>06:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr><tr class="altRow">
<td>07:00 PM</td><td>&nbsp;</td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td><td><a href="AddEvent.aspx?daysel=9/22/2008&amp;id="></a></td>
</tr>
</table>

I would like to have the hyperlink URL ONLY for the table entries that have events. Not the empty times.

Thanks,

Mike
Sep 20 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.