Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Drop down list given below
ASP.NET
<asp:DropDownList ID="ddlExamId" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlExamId_SelectedIndexChanged">
</asp:DropDownList>

it have some value like "1","2" etc. I also use a Grid View to show my database value. Under the Grid View SelectCommand I want to select those data that have examId=ddlExamId.Text. Here is my SelectCommend.
ASP.NET
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:BBAConnectionString1 %>" 
             SelectCommand="SELECT [Id], [tchId], [stdId], [dept], [subject], [courseCode], [quizNum], [examId], [examDate], [gainMark] FROM [quizResult] where examId= 
"<%# this.ddlExamId.Text;%>" />

But this provide me an Error like this
Parser Error Message: The server tag is not well formed.
what should I do. Please help me. I am new in ASP and my English is also week.
Posted
Updated 19-Aug-13 2:20am
v2
Comments
Thanks7872 19-Aug-13 8:19am    
One way is to remove this DataSource and bind your GridView in code. If you want so or comfortable with,let me know.

I have solve this in different way.
C#
protected void FillDdlSession()
{
    SqlCommand cmd = new SqlCommand("SELECT DISTINCT session FROM quizResult ORDER BY session ASC", vcon);
    SqlDataAdapter adp = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    adp.Fill(dt);
    ddlSession.DataSource = dt;
    ddlSession.DataTextField = "session";
    ddlSession.DataValueField = "session";
    ddlSession.DataBind();
    ddlSession.Items.Insert(0, "Choose Session");
}
 
Share this answer
 
Enclose "<%# this.ddlExamId.Text;%>" with single quotation marks as mentioned below :

HTML
'<%# this.ddlExamId.Text;%>'
 
Share this answer
 
Comments
sazzad37 19-Aug-13 8:36am    
No error but can not access ddlExamId value.
CodeBlack 19-Aug-13 8:53am    
instead of this.ddlExamId.Text use this.ddlExamId.SelectedItem.Text and still it doesnt work than check whether query results data or not ?
try using this
ASP.NET
<asp:SqlDataSource ID="Programs_DropdownList" runat="server" ConnectionString="<%$ ConnectionStrings:admConnectionString %>" ProviderName="<%$ ConnectionStrings:admConnectionString.ProviderName %>" 
SelectCommand="SELECT PROGRAM_ID, PROGRAM_NAME FROM PROGRAMS WHERE DEGREE_ID = @DEGREE_ID"><SelectParameters>
<asp:ControlParameter Name="DEGREE_ID" ControlID="Degree_DList" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>


in the place of degree id replace your parameter
 
Share this answer
 
v4
Comments
sazzad37 19-Aug-13 7:58am    
I was try but not work.
sazzad37 19-Aug-13 8:02am    
My main problem is, I can not access ddlExamId by this code "<%# this.ddlExamId.Text;%>" . what should I do?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900