DataList inside user control - ItemCommands don't work if I dont populate List on every page load

Y

yousuf

I have a dataList that pulls from a database table - Im trying to do
the normal Edit, Update, Delete, Cancel - on it.

when I put the following inside a user control - .ascx file it dosn't
work, but when I leave it in the Page, it works fine

<script language="C#" runat="server">

void populateList(){
//prepare data adapter, connect string etc..
DataSet ds = new DataSet();
da.Fill(ds, "PROPERTY");
PropertyList.DataSource = ds.Tables["PROPERTY"].DefaultView;
PropertyList.DataBind();
}

void Page_Load(Object s, EventArgs e){
if(!Page.IsPostBack){
populateList();
}
}

void Delete_Listing(Object Src, DataListCommandEventArgs e){
Response.Write("Delete");
populateList();
}

void Edit_Listing(Object Src, DataListCommandEventArgs e){
PropertyList.EditItemIndex = (int)e.Item.ItemIndex;
populateList();
}

void Cancel_Listing(Object Src, DataListCommandEventArgs e){
PropertyList.EditItemIndex = -1;
populateList();
}

void Update_Listing(Object Src, DataListCommandEventArgs e){
String updateS =
((DropDownList)e.Item.FindControl("editStatusList")).SelectedItem.Value;
Response.Write(updateS+"!");
populateList();
}

</script>

- My datalist displays and all the commands are set up correctly -

If I don't call populateList everytime on Page_Load - the DataList
event commands dont seem to work at all - and If I do call it
everytime, this causes a problem with the edit command - I refill the
list and all the edit values go back to thier orginal values and I
can't maintain the viewstate. I have enabled the viewstate and
autoeventwireup in the @control in the .ascx file

any help would be appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top