简体   繁体   English

如何从复选框单击位于GridView行内的TextChanged事件背后的textBox代码?

[英]How to call textBox codebehind TextChanged event from checkbox click lying inside GridView Row?

I have a Gridview in which each row has a Checkbox and TextBox . 我有一个Gridview,其中每一行都有一个Checkbox和TextBox。 I am doing some work on textchange event as below 我正在做一些有关textchange事件的工作,如下所示

protected void txtRemarks_TextChanged(object sender, EventArgs e)
{
    GridViewRow grow = ((TextBox)sender).Parent.Parent as GridViewRow;

    GenerateCheckedDataAndStore(grow); // Basically populates a datatable from Viewstate


}

This I need to do on click event of checkbox also. 我还需要对复选框的单击事件进行操作。 I have tried using __doPostBack() function but doesnot work. 我尝试使用__doPostBack()函数,但是不起作用。

How can I successfully fire code behind textbox change event from clicking on adjacent checkbox ? 如何通过单击相邻的复选框成功触发文本框更改事件背后的代码? Please help. 请帮忙。

<asp:GridView id="grdView" runat="server">
<Columns>
 <asp:TemplateField ItemStyle-Width="2%">
     <HeaderTemplate>
       <asp:CheckBox runat="server" ID="chkAll" Style="text-align: left !important;" />
     </HeaderTemplate>
     <ItemTemplate>
       <%-- <asp:CheckBox runat="server" ID="chkSelect" AutoPostBack="true" OnCheckedChanged="chkSelect_CheckedChanged" />--%>

       <asp:CheckBox runat="server" ID="chkSelect"  />
       <asp:HiddenField ID="hdnNo" runat="server" Value="<%#Bind('InvoiceNo')%>" />
     </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks" ItemStyle-Width="12%">
     <ItemTemplate>
       <asp:TextBox ID="txtRemarks" runat="server" OnTextChanged="txtRemarks_TextChanged" Text="<%#Bind('Remarks')%>" TextMode="MultiLine"  AutoPostBack="true" ></asp:TextBox>
          <asp:HiddenField ID="hdnRemarks" runat="server" />
       </ItemTemplate>
</asp:TemplateField>
.
.
.
</Columns>
</GridView>

Please note 请注意
My aim is to call GenerateCheckedDataAndStore(grow); 我的目的是调用GenerateCheckedDataAndStore(grow); on checkbox click event. 在复选框上单击事件。

Edit 编辑

As suggested in by @Jared in comments below i am calling textchange from checkchanged of checkbox. 正如@Jared在下面的评论中所建议的那样,我正在从复选框的checkchanged调用textchange。 But strangely the gridview row being captured from checkbpox doesnot udate but remains same as whichever row was selected first. 但是奇怪的是,从checkbpox捕获的gridview行没有审核,但与第一个选择的行相同。

 protected void txtRemarks_TextChanged(object sender, EventArgs e)
 {
        GridViewRow grow= null;
        if(sender is TextBox)
            grow = ((TextBox)sender).Parent.Parent as GridViewRow;
        else if(sender is CheckBox)
            grow = ((CheckBox)sender).Parent.Parent as GridViewRow;
        GenerateCheckedDataAndStore(grow);

  }

Just add to the checkbox following code: 只需将以下代码添加到复选框:

AutoPostBack="true" OnCheckedChanged="txtRemarks_TextChanged"

Update: 更新:

You will need to cast sender to Control instead of TextBox to your action to work. 您需要将发件人强制转换为Control而不是TextBox才能执行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从gridview按钮单击事件代码背后调用javascript函数 - how to call javascript function from gridview button click event codebehind 在Gridview中查找按钮,然后从代码隐藏(c#)单击它 - Find Button inside a Gridview and click it from codebehind(c#) 在GridView中,当单击复选框时,使用Grid的同一行中的JavaScript将标签中的值添加到TextBox - In GridView, when click on checkbox add values from label to TextBox using JavaScript in the same row of Grid 使用Angular如何停止表格行内复选框单击事件的传播()? - with Angular how to stopPropagation() of checkbox click event inside a table row? 从Button click事件中调用Codebehind中的Javascript函数 - Call Javascript function in Codebehind from Button click event 如何使用 c# asp.net 从代码隐藏调用按钮单击事件? - how to call button click event from codebehind using c# asp.net? 如何在输入文本框时触发文本框textchanged事件 - How to fire Textbox textchanged event while typing in textbox 如何在htmltextbox中调用javascript for textchanged事件? - how to call javascript for textchanged event in htmltextbox? 如何调用GridView中的文本框 - How to call a textbox that is in GridView GridView中复选框的单击事件,如何知道它是选中还是未选中? - click event of checkbox in gridview, how to know it was checked or unchecked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM