Sunday, March 11, 2012

dropdown list without page refresh

Hi Swati Jain,

You can place the DropDownList in an UpdatePanel and register the RadioButton as a trigger for the UpdatePanel.

<

asp:UpdatePanelID="updatePanel"runat="server">

<

ContentTemplate>

<asp:DropDownList ... />

</ContentTemplate>

<Triggers><asp:AsyncPostBackTriggerControlID="RadioButtonID"/></Triggers>

</

asp:UpdatePanel>

Hope this helps,


my problem is similar but more complicated i think:

in the AuthorTable, I have AuthorID, State, Name

my dropdownlist is populated by Distinct States from the Author table

my datagridview is populated by Author Details based on the selected State in the dropdownlist, I also enabled edit and insert in the datagridview.

now if i added a new row or edited an existing row with a new State, how can I make the dropdownlist refresh itself to reflex the change?

plz help


Hi ssffcc,

You can use Timer control to update an UpdatePanel at a timed interval.

Check out thishttp://ajax.asp.net/docs/tutorials/IntroToTimerControl.aspx

Hope this helps,


Hi ssffcc,

You can use Timer control to update an UpdatePanel at a timed interval.

Check out thishttp://ajax.asp.net/docs/tutorials/IntroToTimerControl.aspx

Hope this helps,


Hi spvlong,

I am facing the same problem. I did what u mentioned, I mean, I placed the department drop down box in the updatePanel and the company drop down box outside whereby I set the company to be the trigger of the department which is inside the updatePanel. It does not work. If I set autopostback of the company to be true, then it works but it refreshes the whole page, which I don't want.

Help me please...


Hi rrobet,

Can you paste your code so I may find the problem?

This how I tried and It worked.

<asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:DropDownListID="ddlDepartments"runat="server"></asp:DropDownList></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="ddlCompanies"/></Triggers></asp:UpdatePanel>

<asp:DropDownListID="ddlCompanies"runat="server"AutoPostBack="True"OnSelectedIndexChanged="ddlCompanies_SelectedIndexChanged"></asp:DropDownList>

Hope this helps,


Hispvlong, in fact, I did what u have suggested above. but it does not work...

I have attached my codes below. The below codes does not fire anything and the pages just stays without updating anything unless if I add the autopostback to be true forDDLCompany control, which is refreshing the whole page.

SO the problem is, either it doesn't do anything or refreshes the whole page depending on existence of autopostback=true.PLEASE help!!! Thanks

Below is the aspx codes

<

asp:ScriptManagerID="ScriptManager1"runat="server">

</

asp:ScriptManager>

<tablecellpadding="0"cellspacing="0"width="100%">

<tr>

<tdclass="TableHeadingInstruction">

Please select the company followed by the department

</td>

</tr>

<tr>

<tdclass="TableHeadingInstruction"style="height: 19px">

Company:

<asp:DropDownListID="DDLCompany"runat="server"OnSelectedIndexChanged="DDLCompany_SelectedIndexChanged">

<asp:ListItemValue="none">-Select-</asp:ListItem>

</asp:DropDownList><br/><asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

Department:

<asp:DropDownListID="DDLDepartment"runat="server"OnSelectedIndexChanged="DDLDepartment_SelectedIndexChanged"AutoPostBack="True">

<asp:ListItemValue="none">-Select-</asp:ListItem>

</asp:DropDownList>

</ContentTemplate>

<Triggers>

<asp:AsyncPostBackTriggerControlID="DDLCompany"EventName="selectedindexchanged"/>

</Triggers>

</asp:UpdatePanel>

Below is the code forDDLCompany_SelectedIndexChanged

protected

void DDLCompany_SelectedIndexChanged(object sender,EventArgs e)

{

try

{

Comp = DDLCompany.SelectedItem.Value;

if (Comp !="none")

{

DDLDepartment.Items.Clear();

DDLDepartment.Items.Add(

newListItem("-Select-","none"));

_Reader = obj.DBResult(

"portal","select dept from dept where site='" + Comp +"' ");

while (_Reader.Read())

{

DDLDepartment.Items.Add(

newListItem(_Reader["dept"].ToString(), _Reader["dept"].ToString()));

}

_Reader.Close();

}

}

catch (Exception ex)

{

my_err.Visible =

true;

my_err.Text = ex.Message;

}

}


Hi rrobet,

There is no problem with your code. I tried it and it worked.

Do AJAX examples work in your machine?


Ya, fotgot to tell you something I tried before. I include a button without the autopostback=true on the company drop down box. I use the button as the trigger for the UpdatePanel (which containes the department drop down) instead of the company drop down. After executing it, I select the company, then click on the button, well the department gets updated without refreshing the whole page (which means ajax does work), which I wanted but I don't want the button to be there. Furthermore, the button works only for the first time. after that, even the button doesn't do anything. Isn't my case is weird??. Can u figure out the problem?.

No comments:

Post a Comment