I am attempting to create dynamic li elements based on database values with output looking like :
<li id="myUniqueLiID" runat="server"><a href="vaiable url from db">variable string from db</a></li>
The amount of li elements will be determined at run time. I want to go with li elements because I think it leaves me with the most options for manipulation at a later time as oppose to several asp items I have worked with ie asp:ListBox.
Here is the code I am working with so far
SqlDatabase myconnection= new SqlDatabase(@"myconnection string");
DbCommand myproc= myconnection.GetStoredProcCommand("sp_MySP");
using (IDataReader LoadAllItems = myconnection.ExecuteReader(myproc))
{
while (LoadAllItems.Read())
{
// retrieves ID from db
int myID = LoadAllItems.GetInt32(0);
// retrieves string from db
string myName = LoadAllItems.GetString(1);
// I have a static method that builds url based off id
// it takes an int and returns a string
string restURL = MyLibrary.MyClass.StaticURLMethod(myID);
//data bind to li element
myLiID.datasource = LoadAllItems;
//I think I build the li in datatextfield area but not
//sure if that is correct, or how to format.
myLiID.datatextfield = "";
myLiID.databind();
}
}
If I am on the right track please a little guidance on where to go from here. If I am going off in the wrong direction please some guidance to the right path.