Filling a DropDownList on SelectedIndexChanged of another Dropdownlist

Posted by Anu_dgr8 under Regular Expressions on 9/13/2010 | Points: 10 | Views : 9657 | Status : [Member] | Replies : 11
I have something like this:

<asp:UpdateProgress ID="UpdateProgress1" runat="server" 
AssociatedUpdatePanelID="UpdatePanel1" DisplayAfter="0">
<ProgressTemplate>
<asp:Label ID="Label1" runat="server" Text="Please Wait....." CssClass="mainlbl"
ForeColor="Red"></asp:Label><br />
<asp:Image ID="Image1" runat="server" ImageUrl="image.gif"></asp:Image>
</ProgressTemplate>
</asp:UpdateProgress>

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<table>
<tr>
<td>
<asp:RequiredFieldValidator ID="rfCallType" runat="server" ControlToValidate="ddlCallType"
ErrorMessage="Select Call Type" Display="Dynamic" ValidationGroup="Message" InitialValue="---Select---" Text="*">*</asp:RequiredFieldValidator>
<b>Call Type:</b>
</td>
<td colspan="3">
<asp:DropDownList ID="ddlCallType" runat="server" Width="100px" ValidationGroup="Message"
CssClass="DropDownList" AutoPostBack="true" OnSelectedIndexChanged="ddlCallType_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>
<asp:RequiredFieldValidator ID="rfSubCallType" runat="server" ControlToValidate="ddlSubCallType"
ErrorMessage="Select Sub Call Type" Display="Dynamic" ValidationGroup="Message"
InitialValue="---Select---" Text="*">*</asp:RequiredFieldValidator>
<b>Sub Call Type:</b>
</td>
<td class="odd" colspan="3">
<asp:DropDownList ID="ddlSubCallType" runat="server" Width="100px" ValidationGroup="Message"
CssClass="DropDownList">
</asp:DropDownList>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>


And on SelectedIndexChanged of the 1st dropdownlist,i have filled in 2nd dropdownlist.
But its taking a lot of time for the records to come.I want to make it fast..Can somebody tell me how to do this?

Thanks and Regards,
Hoosha Boosha



Responses

Posted by: T.saravanan on: 9/13/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Anu_dgr8,

What do you fill in your 2nd DropDownList?
Are you fill selected item from 1st DropDownList (or) related data of the selected item.

Thanks,

Thanks,
T.Saravanan

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 9/13/2010 [Member] Starter | Points: 25

Up
0
Down
related data of the selected item

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/13/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,
First set AutoPostBack value is True in your 1st DropDownList.

Bind your data through datasource of 1st DropDownList.
Ex:
//Its for First DropDownList Fill

DropDownList1.DataSource=dt;
DropDownList1.DataTextField="Name";
DropDownList1.DataValueField="Id";
DropDownList1.DataBind();

//In DropDownList1 Selected Index Change Event
Just Filter your data from selected value of DropDownList1 into DataTable (or) Pass the Selected Value from DropDownList

string sId=DropDownList1.SelectedValue.ToString();

DropDownList2.DataSource=dtData;
DropDownList2.DataTextField="Name";
DropDownList2.DataValueField="Id";
DropDownList2.DataBind();


Here dt,dtData --> DataTable.

Cheers :)


Thanks,
T.Saravanan

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 9/13/2010 [Member] Starter | Points: 25

Up
0
Down
i am not asking about this..i have already implemented this..the prob is retrieving of the records is very slow...
i want to make the filling of the other dropdownlist faster

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/13/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,
Where will you struck,retrieving data or filling a data into DropDownList.
Can you give your code for my reference?


Thanks,
T.Saravanan

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 9/13/2010 [Member] Starter | Points: 25

Up
0
Down
protected void ddlCallType_SelectedIndexChanged(object sender, EventArgs e)
{
FM_Call_Register._Entity_Solutions.CallType = ddlCallType.SelectedItem.Text;
FillSubCallType();
}

protected void FillSubCallType()
{
ddlSubCallType.Items.Clear();
DataTable dt = new BL_Call_Register().GetSubCallType();
ddlSubCallType.DataValueField = "id";
ddlSubCallType.DataTextField = "type";
ddlSubCallType.DataSource = dt;
ddlSubCallType.DataBind();



}..the other ddl is getting filled...but its takin time to fill..that is the prob

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/13/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Now i am checked my system with large no.of records.I think retrieving a data is take time.If records are huge means filling take a several seconds.But major time is taken for retrieving a Data.Just check your Data retrieving Method.



Thanks,
T.Saravanan

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 9/13/2010 [Member] Starter | Points: 25

Up
0
Down
i checked my stored procedure...the procedure is displaying records within a second...no problem with the procedure here

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: T.saravanan on: 9/13/2010 [Member] [MVP] Silver | Points: 25

Up
0
Down
Hi Anu_drg8,

Sorry for the delay.In my suggestion fully check your code.
If any unwanted method call in selected index event because every event, page load event also call.
Check your page load event.

Thanks :)

Thanks,
T.Saravanan

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Anu_dgr8 on: 9/14/2010 [Member] Starter | Points: 25

Up
0
Down
Hey there's no unwanted method call in my selectedindex event..i have already given you the exact code

Thanks and Regards,
Hoosha Boosha

Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Peermohamedmydeen on: 9/14/2010 [Member] Bronze | Points: 25

Up
0
Down
Hi Anu,

Remove your cssClass attribute from 2 DropDownList and try the same. Some times styling will cause the performance issue.

You had better try the same with out syling. Then apply CssClass one by one.

You have not specified how you are doing your data fetching logic? how many columns you are retrieving from your stored procedure or view?

If all the data fetching logic and stored procedure are efficient then,

ensure the DataSource property needs to be set first, then only your DataTextField propetry to be set as follws.

ddlSubCallType.Items.Clear();

DataTable dt = new BL_Call_Register().GetSubCallType();
ddlSubCallType.DataSource = dt;
ddlSubCallType.DataValueField = "id";
ddlSubCallType.DataTextField = "type";
ddlSubCallType.DataBind();


This order of setting DataSource first and DataValueField ,DataTextField second will boost the performance. Try this.


Anu_dgr8, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response