DataGrid Query

ofusernameu389

New Member
A DataGrid newbie question: I'm using a DataGrid to display records from a SQL Server table with, say, the following data:<BR><BR>ID Name<BR>01 Tom<BR>04 Dick<BR>66 Harry<BR><BR>In the output, I need to display only the name, hyperlinked to another URL, with the ID in its querystring. Something like:<BR><BR><tr><td><a href=http://aspmessageboard.com/archive/index.php/"process.aspx?ID=01">Tom</a></td></tr><BR><tr><td><a href="process.aspx?ID=04">Dick</a></td></tr><BR><tr><td><a href="process.aspx?ID=66">Harry</a></td></tr><BR><BR>Now, to build the href, I need to access the DataReader object bound to the DataGrid, but it doesn't seem to be accessible from the ASPX. What am I missing?<BR><BR>Thanks.<BR>Broto<BR>Presuming that you are Binding to a templated list such as a DataList, DataGrid, or Repeater you could you DataBinder.Eval to Late Bind your values to the template.<BR><BR>Here is some psuedo-code:<BR><BR><ASP:DATALIST id="dtlFoo"><BR> <ITEMTEMPLATE><BR> <A HREF="process.aspx?id=<%# DataBinder.Eval(Container.DataItem, "ID") %>"><BR> <%# DataBinder.Eval(Container.DataItem, "Name") %><BR> </A><BR> </ITEMTEMPLATE><BR></ASP:DATALIST><BR><BR>Check out this link for more info..<BR>http://www.gotdotnet.com/QuickStart/aspplus/default.aspx?url=/quickstart/aspplus/doc/webdatabinding.aspx<BR><BR>Good Programming!<BR>Frodobeing howled at with laughter (because I'm very new to all this).<BR><BR>I think that you could replace the previous example that I gave with this-<BR><BR><A HREF="process.aspx?id=<%# CInt(CType(Container.DataItem, DataRowView)("id")) %>"><BR><%# CStr(CType(Container.DataItem, DataRowView)("name")) %> <BR></A><BR><BR>That would enable you to avoid the Reflection cost incurred at runtime.
 
Back
Top