简体   繁体   中英

How to access HiddenField value in dropdownlist onchange event

How do i access gridview itemtemplate hiddenfield value from the dropdownlist onchange event?. Basically if you see below i'm calling ConfirmStatus on dropdownlist value change and i need to pass hiddenfield value to that method.

<asp:TemplateField Visible="true" HeaderText="Status" >
  <ItemTemplate>

   <asp:DropDownList ID="ddlTransactionList"  Visible = "False" AutoPostBack="True"  OnSelectedIndexChanged="ddlTransactionList_SelectedIndexChanged" 
       onchange=" if(ConfirmStatus(this)!=1){ return false;}"
                              runat="server"/>
   <asp:Label runat="server" ID="lblStatus"  Visible="True" Text='<%# ShowStatus( Container.DataItem ) %>' />
   <input id="hiddenOriginalStatus" type="hidden" runat="server" />
</ItemTemplate>
</asp:TemplateField>

I would rather trigger the onchange from the code behind because that's where you assign and have all the value for.

 protected void gridview1_DataBound(object sender, GridViewRowEventArgs e)
 {
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
          HiddenField hiddenOriginalStatus = (HiddenField)e.Row.FindControl("hiddenOriginalStatus");
          (e.Row.FindControl("ddlTransactionList") as DropDownList).Attributes.Add("onchange", "ConfirmStatus('" + hiddenOriginalStatus.Value + "');");
      }
 }

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