1

我需要在gridview中选择行并隐藏一个按钮,但没有回发,因为我需要保持在gridview中单击的位置,这一步我得到了它,但是当我点击行捕获索引= 0时,但是当我点击按钮时(没有隐藏在这个时间),捕获正确的索引,我该怎么做,感谢您的帮助或任何想法。

我的代码是:aspx:

<asp:UpdatePanel ID="UPGrvConfident" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>
                                <div class="table-responsive" id="gridDentalNetworkContainer" style="overflow: auto; height: 207px; cursor: pointer; padding: 0px">
                                    <asp:GridView ID="gridDentalNetwork" EnableViewState="true" AllowSorting="false" runat="server" GridLines="None" Width="100%"
                                        EmptyDataText="No hay elementos a mostrar." AutoGenerateColumns="false" ClientIDMode="Static"
                                        DataKeyNames="numero" ShowHeaderWhenEmpty="true" HeaderStyle-HorizontalAlign="Center" HeaderStyle-BackColor="Gainsboro" HeaderStyle-BorderWidth="2px" RowStyle-BackColor="White"
                                        RowStyle-BorderColor="White" RowStyle-Font-Size="Smaller" RowStyle-Font-Bold="false" CellPadding="3" CellSpacing="0">
                                        <Columns>
                                            <asp:TemplateField>
                                                <ItemTemplate>
                                                    <asp:Button ID="btnSelect" runat="server" CommandName="Delete" CausesValidation="false" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="Numero" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="Nombre" HeaderText="Nombre" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="Identificacion" HeaderText="Identificación" ItemStyle-Width="10%" HeaderStyle-Width="10%" />
                                            <asp:BoundField DataField="Msg" HeaderText="Nombre">
                                                <ItemStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="ApellidoPaterno" HeaderText="Primer Apellido" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="ApellidoMaterno" HeaderText="Segundo Apellido" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="Contrato" HeaderText="Contrato" />
                                            <asp:BoundField DataField="contratocanal" HeaderText="Contratante" ItemStyle-Width="242px" HeaderStyle-Width="242px">
                                                <ItemStyle HorizontalAlign="Center" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="Titular" HeaderText="Usuario Principal">
                                                <ItemStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="NroDoc" HeaderText="nro_row" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="NroPariente" HeaderText="nro_pariente" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="NroPol" HeaderText="nro_pol" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" HeaderStyle-Width="5px" />
                                            <asp:BoundField DataField="NroAseg" HeaderText="nro_aseg" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="TxtRed" HeaderText="fec_nac" ItemStyle-CssClass="Hides" HeaderStyle-CssClass="Hides" />
                                            <asp:BoundField DataField="Plan" HeaderText="Plan">
                                                <ItemStyle HorizontalAlign="Center" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="fec_alta" HeaderText="Fecha Ingreso" ItemStyle-Width="96px" HeaderStyle-Width="96px">
                                                <ItemStyle HorizontalAlign="Center" />
                                            </asp:BoundField>
                                        </Columns>
                                        <AlternatingRowStyle BackColor="#f2f2f2" />
                                    </asp:GridView>
                                </div>
                            </ContentTemplate>
                        </asp:UpdatePanel>

aspx.vb(代码隐藏)RowdataBound

Protected Sub gridDentalNetwork_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles gridDentalNetwork.RowDataBound
    'e.Row.Cells(0).Style("display") = "none"

    If e.Row.RowType = DataControlRowType.DataRow Then
        e.Row.Attributes("onmouseover") = "this.style.cursor='hand';this.style.textDecoration='underline';"
        e.Row.Attributes("onmouseout") = "this.style.textDecoration='none';"

        Dim btnSelect As Button = TryCast(e.Row.FindControl("btnSelect"), Button)
        btnSelect.CommandArgument = e.Row.RowIndex.ToString()



        'e.Row.Attributes("onclick") = String.Format("document.getElementById('{0}').click();", btnSelect.ClientID)

        e.Row.Attributes.Add("onclick", "document.getElementById('" & btnSelect.ClientID & "').value = '" & e.Row.RowIndex.ToString() & "'; alert(document.getElementById('" & btnSelect.ClientID & "').value); darClick();")
        'e.Row.Attributes.Add("onclick", "var dato = document.getElementById('btnSelect').value; '<%Session['temp']='+ dato +';%>'; alert('<%=Session['temp']%>');")

        'e.Row.Attributes("onclick") = String.Format("document.getElementById('{0}').click();", btnSelect.ClientID)
        'e.Row.Attributes("onclick") = Page.ClientScript.GetPostBackClientHyperlink(gridDentalNetwork, "Select$" + e.Row.RowIndex.ToString())
        'e.Row.Attributes.Add("onclick", String.Format("document.getElementById('{0}').click();", btnSelect.ClientID))
        e.Row.ToolTip = "Clic para seleccionar"
    End If
End Sub

方法:我将 RowDeleting 用于 commandField。

Protected Sub gridDentalNetwork_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs) Handles gridDentalNetwork.RowDeleting
    Dim ListBiored As List(Of MClienteSimple) = New List(Of MClienteSimple)
    Dim grvfila As GridViewRow
    Dim indexx As String = Session("index")
    grvfila = gridDentalNetwork.Rows(e.RowIndex)
    Dim lstClientesConf As New MClienteDentalNetwork
    lstClientesConf = DirectCast(Session("ClientesConf"), List(Of MClienteDentalNetwork))(grvfila.DataItemIndex)

...等..等结束子

4

0 回答 0