简体   繁体   中英

how to get dropdown value inside gridview on button click in c#?

I have tried this but its not working,giving null value:please tell me what have to change in this code.

      protected void Button1_Click(object sender, EventArgs e)
 {
 GridViewRow row;
row = dgData.Rows[0];
DropDownList ddl= (DropDownList)(row.Cells[1].FindControl("ddlCol1"));

}

use

DropDownList ddl= (DropDownList)(row.FindControl("ddlCol1"));

and try and let me know

try this code on click event

foreach (GridViewRow row in GridView1.Rows)
    {
        //Finding Dropdown control  
        DropDownList ddl1 = row.FindControl("ddlTest") as DropDownList;
        if (ddl1 != null)
        {
           // your code here  
        }
    }

@creby i saw your code.

you are adding your dropdown in grid view during row data bound event ok.. but now when you click on the button, all the drop down will be vanished so that's why you will not able to get drop down.

use item template of grid view and then bind dropdown in row data bound event.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM