猿问

如何在下面的 onClick 方法中运行 RowDataBound 方法?

我有一个 GridView 如下


`<asp:GridView ID="gvSearchAll" runat="server" AutoGenerateColumns="False"

     OnPageIndexChanging="searchAll_PageIndexChanging" 

     onrowdatabound="OnRowDataBound">

         <Columns>

              <asp:BoundField DataField="A" HeaderText="A"/>

              <asp:BoundField DataField="B" HeaderText="B"/>

              <asp:BoundField DataField="C" HeaderText="C" />

              <asp:TemplateField HeaderText="Select">

                  <ItemTemplate>

                     <asp:CheckBox ID="RowSelector" runat="server" onclick="checkRadioBtn(this);" />

                  </ItemTemplate>

              </asp:TemplateField>                  

         </Columns>          

 </asp:GridView>`

CodeBehind 上的 OnRowDataBound,我有以下内容:


protected void OnRowDataBound(object sender, GridViewRowEventArgs e)

    {

        if (e.Row.RowType == DataControlRowType.DataRow)

        {               

           e.Row.Cells[3].Attributes.Add("onclick", string.Format("DisplayDetails('{0}');", e.Row.RowIndex + 1));

           e.Row.Attributes["onmouseover"] = "onMouseOver('" + (e.Row.RowIndex + 1) + "')";

           e.Row.Attributes["onmouseout"] = "onMouseOut('" + (e.Row.RowIndex + 1) + "')";

        }        


    }

现在我真正想要的是在单击复选框时运行 DisplayDetails 函数。


 function DisplayDetails(row) {

    var gridView = document.getElementById('gvSearchAll');  

    document.getElementById("A").value = gridView.rows[row].cells[1].innerText;

    document.getElementById("B").value = gridView.rows[row].cells[0].innerText;      

}

我想要做的是,当单击复选框时,我想将特定复选框的行的 A 和 B 列数据填充到某个文本字段。


onClick 函数 checkRadioBtn(this) 执行其他操作。


现在,当前,每当我单击 CheckBox 的整个单元格时,我都会执行 Display Details 函数。我需要的是在 checkRadioBtn(this) 函数中执行 DisplayDetails 函数,但为此我需要类似 (this.row_index) 之类的东西,我无法弄清楚该怎么做。


繁星淼淼
浏览 250回答 1
1回答

ABOUTYOU

为什么要使用复选框,您可以使用链接按钮轻松实现像这样<asp:GridView ID="gvSearchAll" runat="server" AutoGenerateColumns="False"&nbsp; &nbsp; &nbsp;OnPageIndexChanging="searchAll_PageIndexChanging"&nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<Columns>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:BoundField DataField="A" HeaderText="A"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:BoundField DataField="B" HeaderText="B"/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:BoundField DataField="C" HeaderText="C" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:TemplateField HeaderText="Select">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<ItemTemplate&nbsp; >&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:LinkButton&nbsp; ID="RowSelector"&nbsp; Text="Details"&nbsp; &nbsp;OnClientClick = "return Details(this)"&nbsp; runat="server"&nbsp; CommandName="Select" ></asp:LinkButton>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</ItemTemplate>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</Columns>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;</asp:GridView>在脚本上&nbsp;function Details(lnk) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var row = lnk.parentNode.parentNode;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var rowIndex = row.rowIndex - 1;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.getElementById("A").value = gridView.rows[row].cells[1].innerText;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;document.getElementById("B").value = gridView.rows[row].cells[0].innerText;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}
随时随地看视频慕课网APP

相关分类

Go
我要回答