简体   繁体   中英

Value from row with DropDownList on DropDownList Index Changed Event

Code:

    <asp:GridView ID="gv_Recruit" AutoGenerateColumns="False" Width="100%"
     runat="server" OnRowCreated="gvStates_RowCreated" 
        OnRowDataBound="gvStates_RowCreated">
  <Columns>
    <asp:BoundField HeaderText="key" DataField="key" />
    <asp:BoundField HeaderText="Name" DataField="Name" />
    <asp:BoundField HeaderText="Quota" DataField="Quota" />
    <asp:BoundField HeaderText="Session" DataField="Sess" >
      <ItemStyle HorizontalAlign="Center" />
      </asp:BoundField>
    <asp:TemplateField HeaderText="">
      <ItemTemplate>
        <asp:DropDownList ID="ddlCities" Width="100%" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddl_selected">
        </asp:DropDownList>
      </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField HeaderText="Recruiter" DataField="Recruiter" />
    <asp:BoundField HeaderText="MN Phone" DataField="MN Phone" />
    <asp:BoundField HeaderText="Cell Phone" DataField="Cell Phone" />
  </Columns>
</asp:GridView>

Code Behind:

protected void ddl_selected(object sender, EventArgs e)
{
    string _dd_value = ((DropDownList)sender).SelectedValue;
    string trying_to_get = gv_Recruit.Rows[???].Cells[0].Text.ToString(); 
    string also_tried = gv_Recruit.SelectedRow.Cells[0].Text.ToString();
}

Basically what I'm trying to do is get the key value from the first row when the drop down is changed so I can perform an update???

Can't figure this out.

Thanks in advance for the help...

Try

 GridViewRow gRow = (GridViewRow)(sender as Control).Parent.Parent;
 string trying_to_get = string.Empty;
 if (gRow != null) 
 {
    trying_to_get = gRow.Cells[0].Text;
 }

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