Click here to Skip to main content
12,898,392 members (57,692 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 15-Feb-12 1:12am
Updated 15-Feb-12 1:26am
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.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Replace your last line of code with below.

ddlParea.SelectedValue = ddlParea.Items[ddlParea.Items.IndexOf(ddlParea.Items.FindByText(lblPickuparea.Text))].Value;
srinivas vadepally 15-Feb-12 9:00am
i have tried, not working.
still getting the first value.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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.

To make it clear, you can use it in following way
ddlParea.SelectedValue = lblPickuparea.Text;
ddlParea.Items.FindByValue(lblPickuparea.Text).Selected = true;
srinivas vadepally 16-Feb-12 0:54am
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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170424.1 | Last Updated 16 Feb 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100