ASP.NET (C#) Question

Getting value from dropdown in gridview

i am trying to make a "clock in / out site" and one of the functions is for the user to edit old clock ins/outs. i have added a dropdown with 2 values "IND" and "UD". How do i get these values out, and send them to my "CHECKIN" sql value.
I hope you know what iam trying to explain.

this is what it looks like:

enter image description here

The Dropdown:

<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Selected="True">Ind</asp:ListItem>
<asp:ListItem Value="UD">Ud</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>


what ive tried:

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
string val = row.Cells[3].ToString();
SqlDataSource1.SelectParameters.Add("CHECKEDIN", val);
}


and aswell as:

protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)GridView1.FindControl("DropDownList2");
string val = ddl.SelectedValue;
SqlDataSource1.SelectParameters.Add("CHECKEDIN", val);
}


Both of these return "null" tho

Answer

Use RowDataBound event of GridView.

Code

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow 
               && GridView1.EditIndex == e.Row.RowIndex)
    {
        DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList2");
        string val = ddl.SelectedValue.ToString();
        SqlDataSource1.SelectParameters.Add("CHECKEDIN", val);
    }
}