本文介绍了数据处理后清除控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用一个带有按钮的用户控件,该按钮触发一个事件以绑定Webform上的gridview ...
在单击Web窗体上的按钮并在gridview上发生某些过程之后,我希望gridview的可见性变为false....
但是执行的代码却不起作用..即代码执行没有问题,但是gridview仍然可见.....
这是背后的代码
I am using a user control which has a button in it which fires an event to bind a gridview which is on the webform...
After a button on a webform is clicked and certain process happens on the gridview I want that the gridview visibility becomes false....
However the code executed but it does''t work....i.e. the code executes without problems but the gridview is still visible.....
this is the code behind
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
btn = DirectCast(Search1.FindControl("btn_search"), Button)
If btn IsNot Nothing Then
AddHandler btn.Click, AddressOf Me.btn_Click
End If
End Sub
Protected Sub btn_deallocate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_deallocate.Click
Dim bed_no As String
Dim ejamaatId As String
Dim no_rows As Integer
'Getting the ejamaatId of the student against which the checkbox has been checked
For Each gvrow_student As GridViewRow In gvw_search.Rows
Dim cb As CheckBox = DirectCast(gvrow_student.FindControl("chk_student"), CheckBox)
If cb IsNot Nothing Then
If cb.Checked Then
ejamaatId = gvw_search.DataKeys(gvrow_student.RowIndex).Value.ToString()
bed_no = gvw_search.Rows(gvrow_student.RowIndex).Cells(7).Text.ToString()
Try
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Open()
Dim cmd As New SqlCommand("spr_BedAllocation", con)
cmd.CommandType = CommandType.StoredProcedure
Dim modepar1 As New SqlParameter("@mode", "Deallocate-Bed")
cmd.Parameters.Add(modepar1)
cmd.Parameters.AddWithValue("@ejamaatID", ejamaatId)
cmd.Parameters.AddWithValue("@bed_no", bed_no)
cmd.Parameters.AddWithValue("@hostelID", 1)
no_rows = cmd.ExecuteNonQuery()
con.Close()
Catch ex As Exception
End Try
End If
End If
Next
'ClearControls()
If no_rows > 0 Then
'ClientScript.RegisterStartupScript(GetType(Page), "MsgScript", "alert('students deallocated successfully');", True)
gvw_search.DataSource = Nothing
gvw_search.DataBind()
'If gvw_search.Rows.Count = 0 Then
gvw_search.Visible = False
btn_deallocate.Visible = False
grid_div.Visible = False
'End If
End If
End Sub
推荐答案
这篇关于数据处理后清除控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!