Datalist issues

02-24-2007, 11:52 PM
First off , thanks for your time...

I have a datalist control in my page.

<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" DataSourceID="AccessDataSource3"
Style="z-index: 102; position: relative; top: 3px;" SelectedItemStyle-BackColor="yellow" SelectedIndex="1" OnSelectedIndexChanged="DataList1_SelectedIndexChanged" OnItemCommand="DataList1_ItemCommand"


And the DataList1_ItemCommand function is as follows

protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
string cmd = e.CommandName;
if (cmd == "select")

DataList1.SelectedIndex = e.Item.ItemIndex;

The error I get is that DataList1 does not exist in the current context...This happens even if I put the statement in the Page_Load function..Should i set the control to public someplace coz all I did was to drag and drop the control onto the form...Thanks again for any suggestions...

02-25-2007, 12:29 AM
Guess I solved it.
Seems to be a known bug with VS 2005. Doesn't add the required lines of code to the cs file...protected System.Web.UI.WebControls.DataList DataList1; If you add it manually it says that the control is already defined.

Hence, I had to do:

dlistctrl = (DataList)Page.FindControl("DataList1");

to get the control and then use it.

Hope this helps...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum