Click here to Skip to main content
Rate this: bad
good
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
Edited 15-Feb-12 1:26am
v2
Comments
Sudip Saha at 15-Feb-12 7:29am
   
your dropdownlist control is in gridvie?
srinivas vadepally at 15-Feb-12 7:34am
   
no sudip.
it is outside of the gridview control
Venkatesh Mookkan at 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
good
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;
  Permalink  
Comments
srinivas vadepally at 15-Feb-12 9:00am
   
i have tried, not working.
still getting the first value.
Rate this: bad
good
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.
 
[Edit]
To make it clear, you can use it in following way
ddlParea.SelectedValue = lblPickuparea.Text;
//or
ddlParea.Items.FindByValue(lblPickuparea.Text).Selected = true;
  Permalink  
v2
Comments
srinivas vadepally at 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 at 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
0 OriginalGriff 6,034
1 Sergey Alexandrovich Kryukov 4,838
2 Peter Leow 3,129
3 Maciej Los 3,079
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 16 Feb 2012
Copyright © CodeProject, 1999-2014
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