can any one clear my error in DropDownList? [Resolved]

Posted by Tejamanimala under ASP.NET on 3/13/2013 | Points: 10 | Views : 1841 | Status : [Member] | Replies : 17
Hi,I have dropdownlist in one page,in that page when i am executing this,am getting error as follows......
Compilation Error

Description:
An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message:
CS0123: No overload for 'DropDownList2_SelectedIndexChanged' matches delegate 'System.EventHandler'

Line 113:style="color: #006600; font-weight: 700" Text="Select The Domain"></asp:Label>
Line 114:<span class="style21"><strong>&nbsp;</strong></span>&nbsp;&nbsp;
Line 115:<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
Line 116: onselectedindexchanged="DropDownList2_SelectedIndexChanged">
Line 117:<asp:ListItem>--Select--</asp:ListItem>


Please can any one suggest me what should i do,because i tried it,but id didn't find whee should i change.

manimala


Responses

Posted by: Somu475 on: 3/13/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi Tejamanimala,

Sorry, I'm leaving now... I'll definitely reply for your new doubt tomorrow.

Mark as answer for the previous post if it helped you.

-Somu

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

Posted by: Jayakumars on: 3/13/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

post your code.

Mark as Answer if its helpful to you

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

Posted by: Somu475 on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
Do check whether you have added the code of on selected index changed event.

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)

{

}

Please update the code so that we can analyse properly.

-Somu

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

Posted by: Tejamanimala on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
my c# code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace newonlineexam
{
public partial class StudentHome : System.Web.UI.Page
{

SqlConnection con = new SqlConnection("user id=sa;password=Ektha@2013;database=Database1;Data Source=IPOG-A95E1056D3");
protected void Page_Load(object sender, EventArgs e)
{


}
protected void DropDownList2_SelectedIndexChanged(object sender, String val)
{
con.Open();
ListItem li;

for (int i = 0; i < DropDownList2.Items.Count; i++)
{
li = DropDownList2.Items[i];
if (li.Value == val)
{
DropDownList2.SelectedIndex = i;
break;
}

}
}
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Text.ToString();

}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("ToProceed.aspx");
}
}
}

manimala

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

Posted by: Somu475 on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
You can't use like this..

protected void DropDownList2_SelectedIndexChanged(object sender, String val) 

{
}


Try like this... Change 2nd argument as follows...
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)

{
}


Mark as answer if it helps you.

-Somu

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

Posted by: Tejamanimala on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
ok,then where should i use string val;
it is not working under
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)

{

}

manimala

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

Posted by: Tejamanimala on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
If i use like as follows,then i am getting the error in place of if (li.Value == val).
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
ListItem li;
String val;
for (int i = 0; i < DropDownList2.Items.Count; i++)
{
li = DropDownList2.Items[i];
if (li.Value == val)
{
DropDownList2.SelectedIndex = i;
break;
}

}
}

manimala

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

Posted by: Somu475 on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
Can you tell me what actually you want to do in SelectedIndexChanged.

From where you were passing that string val before...??

-Somu

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

Posted by: Somu475 on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
I think you want to compare a string value with the Dropdown Items,
If that is present in Dropdown then you want it to be selected in Dropdown.
Am I correct..?? If so which string you want to compare..??

-Somu

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

Posted by: Tejamanimala on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
Actually when student want to write the exam,he goes to the Student Home Page in my project,in this page he can select any one domain in dropdownlist,he want to write the exam.after selecting the domain in dropdownlist,he should be get the message as "Your Selected Domain is:---".
After that he clicks on the continue button,this continue button,takes it into the question paper page.
my source code is...
<p class="style19">
<asp:Label ID="Label1" runat="server" ForeColor="#339933"
style="color: #006600; font-weight: 700" Text="Select The Domain"></asp:Label>
<span class="style21"><strong>&nbsp;</strong></span>&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>.NET</asp:ListItem>
<asp:ListItem>JAVA</asp:ListItem>
<asp:ListItem>Testing Tools</asp:ListItem>
<asp:ListItem>SQl Server</asp:ListItem>
</asp:DropDownList>
</p>
<p class="style19">
&nbsp;</p>
<p class="style19">
&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" Font-Bold="True"
onclick="Button1_Click" Text="Submit" />
</p>
<p class="style19">
<strong><span class="style22">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Your Selected Domain Is :&nbsp;</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </strong>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<p class="style19">
&nbsp;&nbsp;
<asp:LinkButton ID="LinkButton1" runat="server" Font-Bold="True"
ForeColor="#993366" onclick="LinkButton1_Click" style="color: #993366"
PostBackUrl="~/ToProceed.aspx">Continue</asp:LinkButton>
</p>

manimala

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

Posted by: Tejamanimala on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
ya u r write,i want to compare the string value,with drop-down list item,and the item value is nothing but what ever we are giving in the dropdownlist.I am sorry may be my c# code is wrong,can you please tell me the code for my requirement which i provide you?

manimala

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

Posted by: Somu475 on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
Then do like this.

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Text.ToString();
}

-Somu

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

Posted by: Tejamanimala on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
ok,Again i am getting same error. But if we write
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Text.ToString();
}
like this,
then for submit button what should i write,i mean when i click on the submit button only it will display the message as "your Selected domain is:..." kada

manimala

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

Posted by: Somu475 on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
If you want to display that message only on Submit button click then no need of using DropDownList2_SelectedIndexChanged event.

You can remove the following code..
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) 

{
Label2.Text = DropDownList2.SelectedItem.Text.ToString();
}

And add only this..
protected void Button1_Click(object sender, EventArgs e) 

{
Label2.Text = DropDownList2.SelectedItem.Text.ToString();
}


Note: Don't forget to remove onselectedindexchanged="DropDownList2_SelectedIndexChanged" in front end.

-Somu

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

Posted by: Jayakumars on: 3/13/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi

try this code

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Text.ToString();
}

protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text = "your Selected domain is:" + DropDownList2.SelectedItem.Text.ToString();
}

Mark as Answer if its helpful to you

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

Posted by: Tejamanimala on: 3/13/2013 [Member] Starter | Points: 25

Up
0
Down
Thank You somu garu,for your valuable suggestions.it's working.thank you so much.
And i have another doubt,that is when an Exam instructor wants to add questions into database,for student examinations,then exam instructor how can add the questions,can you please tell me?

manimala

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

Posted by: Jayakumars on: 3/13/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Add this filed ur table

Qid,Questions

Mark as Answer if its helpful to you

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

Login to post response