我有一个Gridview和一个按钮。 当我点击按钮然后显示消息,但之后我的Gridview的格式不像以前那样正确。
请在下面的图片中查看更多内容: Gridview incorrect format after close message
我使用下面的代码显示消息:
HttpContext.Current.Response.Write("<script>alert('Đã tồn tại nguồn đơn " & name & ". Bạn không thể tạo thêm được nguồn đơn này nữa')</script>")
Return
=&GT;如何保持普通格式?
以下代码我使用:
Private Sub grvData_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grvData.RowCommand
lblError.Text = String.Empty
Dim commandNameType As String = String.Empty
Try
If e.CommandName = "Insert" Then
commandNameType = "thêm"
Dim txtName As TextBox = DirectCast(grvData.FooterRow.FindControl("txtNewName"), TextBox)
Dim cboStatus As DropDownList = DirectCast(grvData.FooterRow.FindControl("ddlNewStatus"), DropDownList)
lblError.Text = String.Empty
Try
If String.IsNullOrEmpty(txtName.Text) Then
Return
End If
Dim pSource As New TblPetitionSource
pSource.Name = txtName.Text
pSource.Lastupdate = Now.ToString("yyyy/MM/dd HH:mm:ss")
pSource.StatusFlag = 1
pSource.UpdateBy = "ADMIN"
Dim db As New ProcuracyDataContext
Dim lst = (From p In db.TblPetitionSource Where p.Name = txtName.Text Select p).ToList()
If lst.Count > 0 Then
HttpContext.Current.Response.Write("<script>alert('Đã tồn tại nguồn đơn . Bạn không thể tạo thêm được nguồn đơn này nữa')</script>")
Return
End If
db.TblPetitionSource.InsertOnSubmit(pSource)
db.SubmitChanges()
BindData()
Catch ex As Exception
lblError.Text = ex.Message
End Try
End If
Catch ex As Exception
lblError.Text = "Lỗi không " & commandNameType & " được bản ghi này <br />" & ex.Message
End Try
End Sub
这是我用于MergeCells的代码:
Private Sub grvData_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grvData.RowDataBound
Try
If e.Row.RowType = DataControlRowType.Header Then
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells(e.Row.Cells.Count - 1).ColumnSpan = 2
e.Row.Cells(e.Row.Cells.Count - 1).Text = "Thao tác"
End If
If e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells.RemoveAt(e.Row.Cells.Count - 1)
e.Row.Cells(e.Row.Cells.Count - 1).ColumnSpan = 4
End If
Catch ex As Exception
Throw New Exception(ex.Message, ex)
End Try
End Sub
您能否在这些文件中看到更多细节: https://drive.google.com/open?id=0B6NcrBkoDTV5TV9QcFFUWUpnTFk
和点击按钮后的表单: Web form after click button
非常感谢你!