Click here to Skip to main content
12,690,575 members (32,269 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#3.0 C# 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
Updated 17-Jan-13 7:44am
Sandeep Mewara 17-Jan-13 12:45pm
creating dynamic dropdown in inside gridview.i want to retrive selected value from dropdown.
Not clear.
Sergey Alexandrovich Kryukov 17-Jan-13 18:20pm
I answered, because the bug is way too clear, please see.

1 solution

Rate this: bad
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.

Sergey Alexandrovich Kryukov 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 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".

Sandeep Mewara 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 17 Jan 2013
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