Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
Hai sir,
 

I am creating dynamic dropdown in inside gridview.i want to retrive selected value from dropdown. But i get null value.Please solve my problem
 for (int i = 0; i < GridView2.Rows.Count; i++)
{
    DropDownList box = (DropDownList)GridView2.Rows[i].Cells[1].FindControl("murali" + (i + 1).ToString());
}  

I get null value at "box"
Posted 17-Jan-13 7:28am
Edited 17-Jan-13 7:44am
v2
Comments
Sandeep Mewara at 17-Jan-13 12:45pm
   
creating dynamic dropdown in inside gridview.i want to retrive selected value from dropdown.
Not clear.
Sergey Alexandrovich Kryukov at 17-Jan-13 18:20pm
   
I answered, because the bug is way too clear, please see.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are doing it so wrong! FindControls looks for control, not for any data in control. It looks for some control by control's name. You result just tells you there is no control with that name. Naturally, you never created one; as this is just part of the data.
 
You can use DropDownList.Items.IndexOf instead.
 
—SA
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 17-Jan-13 18:16pm
   
[OP commented:]
 
I am not getting dropdown event as suggested by you because i have created the dropdown in gridview dynamically.
Sergey Alexandrovich Kryukov at 17-Jan-13 18:19pm
   
Who are you asking about it?
You did not ask anything about the event. I answered your question if full, please accept it formally (green button), or ask your follow-up question.
Perhaps, if you describe what you want to achieve, I'll answer about the event, but this is a different question.
 
Also, keep in mind that 1) I did not get notification of your post; next time, comment on the post of a person you want to talk to; 2) never add a solution just to comment; "Add your solution here" is reserved for the cases when you are going to provide some help in response to some question".
 
—SA
Sandeep Mewara at 17-Jan-13 23:53pm
   
My 5! Totally agree. He says he is creating dropdown dynamically and trying to access them but the code says something else. Totally unclear - wrong approach to do it.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,373
1 OriginalGriff 6,466
2 Peter Leow 3,567
3 Zoltán Zörgő 3,316
4 Richard MacCutchan 2,397


Advertise | Privacy | Mobile
Web03 | 2.8.150123.1 | Last Updated 17 Jan 2013
Copyright © CodeProject, 1999-2015
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