如何在更新面板中的Gridview中找到按钮ID?

时间:2017-05-10 05:04:44

标签: asp.net vb.net gridview

  

我无法找到更新按钮的ID是你的任何方式   找到gridview内部的更新按钮ID,网格是   在更新面板内。   写入脚本寄存器是页面加载。我这样写   当前更新按钮在第二次单击时触发

ASPX代码

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Me.ErrorLabel.Text = String.Empty
            Me.ErrorLabel.Visible = False
            Dim pageName = HttpContext.Current.Request.Url.AbsoluteUri
    If (Not Page.IsPostBack) Then
                tblNAbers.Visible = True
                BindBLDGDropDown("adonepudi")
            End If


          For Each gvr As GridViewRow In GridSubMeter.Rows
            If gvr.RowType = DataControlRowType.DataRow Then
            Dim button As Button = CType(gvr.FindControl("btn_Update"), Button)
            If Not (button Is Nothing) Then
                                  ScriptManager.GetCurrent(Me).RegisterPostBackControl(button)

end sub
Protected Sub ddlBldgId_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ddlBldgId.SelectedIndexChanged
        If ddlBldgId.SelectedItem.Value != -1 Then
 BindGridSubMeter()
end sub
  Protected Sub BindGridSubMeter()
        Dim conMRI As New ConnectionMRI()
        Dim ds As DataSet = conMRI.NabersSubMetergetData(ddlBldgId.SelectedItem.Value, ddlRating.SelectedItem.Value)
        TextExclusions.Text = ds.Tables(1).Rows(0).Item(0).ToString()
        UpdatePanelExclusions.update()
        With GridSubMeter
            .DataSource = ds.Tables(0)
            .DataBind()
        End With
    End Sub
 Protected Sub GridSubMeter_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridSubMeter.RowEditing
        GridSubMeter.EditIndex = e.NewEditIndex
        Me.BindGridSubMeter()
    End Sub

    Protected Sub GridSubmeter_PageIndexChanging(sender As Object, e4 As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridSubMeter.PageIndexChanging
        GridSubMeter.PageIndex = e4.NewPageIndex
        Me.BindGridSubMeter()
    End Sub

    Protected Sub GridSubMeter_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridSubMeter.RowUpdating
        Dim txtMeterIdn As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txtMeterIdn"), TextBox)
        Dim txCTFact As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txCTFact"), TextBox)
        Dim txReadStartDate As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txReadStartDate"), TextBox)
        Dim txReadEndDate As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txReadEndDate"), TextBox)
        Dim txStartKwh As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txStartKwh"), TextBox)
        Dim txEndKwh As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txEndKwh"), TextBox)
        Dim txBillPer As TextBox = CType(GridSubMeter.Rows(e.RowIndex).FindControl("txBillPer"), TextBox)

        Dim MeterIdn As String = txtMeterIdn.Text.Trim.ToString()
        Dim CTFact As Decimal = Convert.ToDecimal(txCTFact.Text)
        Dim ReadStartDate As Date = Date.Parse(txReadStartDate.Text)
        Dim ReadEndDate As Date = Date.Parse(txReadEndDate.Text)
        Dim StartKwh As Decimal = Convert.ToDecimal(txStartKwh.Text)
        Dim EndKwh As Decimal = Convert.ToDecimal(txEndKwh.Text)
        Dim billper As Decimal = Convert.ToDecimal(txBillPer.Text)

        Dim leasid As String = GridSubMeter.Rows(e.RowIndex).Cells(0).Text.Trim.ToString()
        Dim suitid As String = GridSubMeter.Rows(e.RowIndex).Cells(1).Text.Trim.ToString()
        Dim occupant As String = GridSubMeter.Rows(e.RowIndex).Cells(2).Text.Trim.ToString()
        GridSubMeter.EditIndex = -1
        Dim conMRI As New ConnectionMRI()
        conMRI.NaberSubmeter(ddlBldgId.SelectedItem.Value, leasid, suitid, occupant, MeterIdn, CTFact, ReadStartDate, ReadEndDate, StartKwh, EndKwh, billper)
        Me.BindGridSubMeter()
    End Sub

vb.net代码

Test t

2 个答案:

答案 0 :(得分:0)

尝试删除

For Each gvr As GridViewRow In GridSubMeter.Rows
            If gvr.RowType = DataControlRowType.DataRow Then
            Dim button As Button = CType(gvr.FindControl("btn_Update"), Button)
            If Not (button Is Nothing) Then
                                  ScriptManager.GetCurrent(Me).RegisterPostBackControl(button)

从页面加载并在最后将其粘贴到BindGridSubMeter

答案 1 :(得分:0)

试试这个

For Each gr As GridViewRow In Grid_Records.Rows
Dim bt As Button = DirectCast(gr.Cells(0).FindControl("btn_Update"), Button)
Dim here As bt.properties

下一步