Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating the dataBind to a Repeater/Datalist...

Status
Not open for further replies.

pwilson

MIS
Sep 26, 2003
38
US
I have a DropDownList and a Repeater which is based on the selection in that List. When the SelectedIndex is changed I need the Data in the Repeater to be updated. (It doesn't have to be a repeater, I used that because it was displaying the recordset)

my aspx file is basically.
<asp:DropDownList id=&quot;teamList&quot; AutoPostBack=&quot;true&quot; OnSelectedIndexChanged=&quot;teamList_Changed&quot; />
<asp:Repeater id=&quot;navBar&quot; runat=&quot;server&quot;>
<ItemTemplate><%# DataBinder.Eval (Container.DataItem, &quot;AreaName&quot;) %>
</ItemTemplate>
</asp:Repeater>

I cut out some of the attributes like the datatext fields

I have a code behind class which is basically

// Navbar.ascx..cs
// NavBar creates a drop down list of teams and a clickable list of the Areas

namespace FCU
{
Using ...

public class NavBar : System.Web.UI.UserControl
{

protected DropDownList teamList;
protected Repeater navBar;
OleDbConnection conn1;

private void Page_Load(object sender, System.EventArgs e)
{
conn1 = new OleDbConnection(...)
DisplayPage();
}}

public void teamList_Changed(object sender, EventArgs e)
{ //called when the dropdownlist is changed
OleDbDataReader reader1 = null;
try
{
...
//get the selected index
...
teamList.SelectedIndex = selindex;
}
finally
{
if(reader1!=null) reader1.Close();
if(conn1 !=null) conn1.Close();
}

}

private void DisplayPage()
{//Display function called in Page_Load

Fill_teamList(); This Fills the Drop Down Box, The contents of the Drop Down box do not change and the List is working as it should

Fill_Areas();This is what I use to fill the Repeater
}

private void Fill_Areas()
{
variable initilization
...
try
{

Here I build My Sql Statement based on the selection in the DropDownList

This part of the program functions. I can feed in initial data. (which index is selected) And the correct sql will be spit out, but only the first time

readernavbar = cmdnavbar.ExecuteReader();
navBar.DataSource = readernavbar;
navBar.DataBind();

}
finally
{
}
}

private void Fill_teamList()
{
As I said, I can fill the DropDownList Once, and it only needs to be filled once.
}

}
//end of class


I took out alot of the extraneous code, and hopefully you can understand what I am trying to Do.

Basically when I change my selection in the drop down list I can see changes using response.write, but the Data in the Repeater Does Not Change. It seems like it is beind bound once and then will not be rebound to the new sqlquery.

I tried only calling DisplayPage in (!Page.IsPostBack())
but the same results.

i tried setting the EnableViewState of the Repeater to false, thinking that it would then load new data for it. But it did not.

I'm not sure If I am heading in the wrong direction or what.

I have noticed that the Event handler processes the onSelected index Changed After the page_load, I am not really sure how that is helpful. Processing things in the EventHandler Do it after the fact..

I have seen this functionality on other pages(maybe not aspx) but usually with two dropdownlists.
&quot;Choose you OS in the first Box&quot; Then It fills the Second Listbox with other information.

I have accomplished this with ASP, But I'm trying to learn ASP.NET

Thanks for any suggestions

Phillip
 
Would I have to Create X number of Repeaters All Invisible. Add them to the page and set the one for the current selected Index to visible? I don't even know how to begin that. Such as how would you set the Id's.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top