Sunday, February 1, 2009

GRIdview Updating Write Query With conditions VB.ne

Protected Sub grdCategory_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs)
Try
Dim strCatid As String
Dim strCatprefix As String
Dim strCatname As String
Dim strCatdesc As String
Dim strSql As String
Dim boolGrouped As Boolean


strCatid = CType(grdCategory.Rows(e.RowIndex).FindControl("txtCategoryId"), TextBox).Text
strCatprefix = CType(grdCategory.Rows(e.RowIndex).FindControl("txtcategoryeditprefix"), TextBox).Text
strCatname = CType(grdCategory.Rows(e.RowIndex).FindControl("txtCategoryName"), TextBox).Text
strCatdesc = CType(grdCategory.Rows(e.RowIndex).FindControl("txtcategorydesc"), TextBox).Text
boolGrouped = CType(grdCategory.Rows(e.RowIndex).FindControl("chkGrdcategorygroupedit"), CheckBox).Checked
Dim varGroup As Int32
If boolGrouped Then
cmd.CommandText = "select b.catid,a.catid from tblcat a,tblcat b where a.pcatid=b.catid and b.catid=" & strCatid
cmd.Connection = con.createConnection(Session("site"))
Dim drCategory As SqlDataReader = cmd.ExecuteReader
If drCategory.HasRows = True Then
varGroup = 1
'lblCheck.Text = ""
Else
varGroup = 0
'lblCheck.Text = "The Category Have No Sub-Categories"
End If
drCategory.Close()
cmd.Dispose()
Else
varGroup = 0
End If
strSql = "update tblcat set grouped=" & varGroup & ","
If strCatprefix <> "" Then
strSql += " catprefix='" & strCatprefix & "'"
End If
If strCatname <> "" Then
strSql += ",catname='" & strCatname & "'"
End If
If strCatdesc <> "" Then
strSql += ",catdesc='" & strCatdesc & "'"
End If
strSql += " where catid='" & strCatid & "'"
cmd.CommandText = strSql
cmd.Connection = con.createConnection(Session("site"))
cmd.ExecuteNonQuery()
lblResult.Text = "Updated"
cmd.Dispose()
' grdCategory.EditItemIndex = -1
grdCategory.EditIndex = -1
Bind_Categories_DataGrid()
Catch ex As Exception
lblResult.Text = ex.Message
End Try
End Sub

Protected Sub grdCategory_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs)
grdCategory.EditIndex = -1
Bind_Categories_DataGrid()
End Sub

No comments:

Post a Comment