Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Hi,
I've enabled the cascading dropdownlist option in the gridview and its working fine. When i'm trying to select the dropdownlist with the values and adding the new rows, then it is showing "Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.".

Please help me on this. The same is occuring when saving the button too.
Posted
Comments
Vinay Mistry 21-Aug-14 1:10am    
Please describe your query.
[no name] 21-Aug-14 1:43am    
I've two dropdownlist in the gridview.

1. Skill Type
2. Skill

Skill should populate the value based upon the selected Skill Type value. For this i've enabled the Cascading Dropdownlist solution using WebService and it works now.

In Gridview i'm adding the rows after selecting the values in these two dropdowns. By adding the application gives Invalid postback error. Please help.
Vinay Mistry 21-Aug-14 2:33am    
Are you adding row dynamically or using rebind?
[no name] 21-Aug-14 3:00am    
S dynamic rows by clicking an image button (+).
Vinay Mistry 21-Aug-14 3:07am    
Then have you tried to set enableEventValidation="true" or enableEventValidation="false"

1 solution

So, I would suggest you to go for simple DropDownList. Don't go for Cascade and all.

Handle the SelectedIndexChanged Event of first DropDownList and inside that Bind the other DropDownList. As simple as that.
 
Share this answer
 
Comments
[no name] 21-Aug-14 8:03am    
I did this already but i can't get the result set as i'm keeping the dropdownlist in the gridview. Please suggest how to keep it. Please give me a sample code of that. Thanks.
What is the issue if you have it inside the GridView? I don't see any issue.

See the example - Raising DropDownList SelectedIndexChanged From GridView Control

You can get the DropDownList inside the SelectedIndexChanged. Then the GridView. Then get the other DropDownList. Something like... Then populate that. Got me? If not, ask me more. I would love to answer.

DropDownList Skill = (DropDownList)grdrDropDownRow.FindControl("yourDropDownSkillID");
[no name] 21-Aug-14 8:30am    
For Ex: I'm having Country and State in my Gridview as both Country & State as Dropdownlist. Now after selecting the Country, in the state dropdownlist the states which are tagged to that particular country should list down the values from the database. How to do this without using cascading? Please give the sample code in C#. Thanks.
[no name] 21-Aug-14 9:02am    
This is the code using inside the Gridview_RowDataBound

if (e.Row.RowType == DataControlRowType.DataRow)
{
con.Open();
DropDownList ddl = e.Row.FindControl("DropDownList2") as DropDownList;
SqlCommand cmd = new SqlCommand("Select a1.CountryName from Country a1 order by a1.CountryName", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddl.DataSource = ds;
ddl.DataTextField = "CountryName";
ddl.DataValueField = "CountryName";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("--Select--", "0"));

con.Open();
DropDownList ddl2 = e.Row.FindControl("DropDownList3") as DropDownList;
//DropDownList ddl3 = e.Row.FindControl("DropDownList2") as DropDownList;
SqlCommand cmd1 = new SqlCommand("Select a1.StateName from State a1 Join Country a2 on a1.CountryName=a2.CountryName where a2.CountryName='" + ddl.SelectedItem.Selected + "' order by a1.StateName", con);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet de = new DataSet();
da1.Fill(de);
con.Close();
ddl2.DataSource = de;
ddl2.DataTextField = "StateName";
ddl2.DataValueField = "StateName";
ddl2.DataBind();
ddl2.Items.Insert(0, new ListItem("--Select--", "0"));
}


But this is not getting the State Names which are under the selected Country.
Look, you are doing it wrong. The second part which binds the States should be inside the SelectedIndexChanged Event of the Country DropDownList. First part is fine. See the link which I have given you in my previous comment. That shows how to get the current DropDownList and the current Row. Then from the Current Row, you can get the State DropDown as I suggested in my comment.

After you get that, then just use the code you already have and bind.

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