Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends,

i have a gridview in sample.aspx which contains name, mobile pickuparea etc. and Update linkbutton in Gridview.

when i click on linkbutton these values have to be saved in the respective controls.
Autopostback property of pickuparea is enabled and dropdownlists are binded in
(!ispostback) of the page_load event.

the problems comes with the follwoing area:

//Under row command:
   if (e.CommandName == "update")
{
 int index = Convert.ToInt32(e.CommandArgument) % GridView1.PageSize;
                GridViewRow row = GridView1.Rows[index];
//----------
//----------
Label lblPickuparea = (Label)row.FindControl("Label7");
ddlParea.SelectedItem.Text= lblPickuparea.Text;//Here selectitemtext value is 3

 ddlParea.SelectedValue = ddlParea.Items.FindByText(lblPickuparea.Text).Value;//here selected value is -1
}


So i want to get the selectedvalue as the selecteditem.text value.
Based on this i have to bind another dropdownlist.

I have done enableviewstate="true" of dropdownlist and page.

Please do help me.

Thanking you all.
Posted
Updated 15-Feb-12 1:26am
v2
Comments
Sudip Saha 15-Feb-12 7:29am    
your dropdownlist control is in gridvie?
srinivas vadepally 15-Feb-12 7:34am    
no sudip.
it is outside of the gridview control
Venkatesh Mookkan 15-Feb-12 22:21pm    
Hi Srinivas,
You need to post your HTML content to under the Page Design. The way you explained above is hard to picture your page. Please post the HTML and give a reply to this comment. I will see what I can do.

Are you sure you want to use FindByText? 3 doesn't seem like any area. I guess, you are confused between FindByText and FindByValue. If you share HTML of your dropdown, I'm sure you'll get proper answer.

[Edit]
To make it clear, you can use it in following way
C#
ddlParea.SelectedValue = lblPickuparea.Text;
//or
ddlParea.Items.FindByValue(lblPickuparea.Text).Selected = true;
 
Share this answer
 
v2
Comments
srinivas vadepally 16-Feb-12 0:54am    
Prerak,
the selectedvalue of the text(lblPickuparea.text) is 3.
So i should go with findbytext only na??
Prerak Patel 16-Feb-12 4:24am    
It is still confusing. Your html for dropdownlist would have helped better. As far as I understand, you have misunderstood the function. I updated the answer. I hope that will make it clear and solve your problem. If not, post the html generated for your ddl.
Replace your last line of code with below.

C#
ddlParea.SelectedValue = ddlParea.Items[ddlParea.Items.IndexOf(ddlParea.Items.FindByText(lblPickuparea.Text))].Value;
 
Share this answer
 
Comments
srinivas vadepally 15-Feb-12 9:00am    
i have tried, not working.
still getting the first value.

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