-------------------- view desing Girid -----------
bgcolor="#9999FF">
<div style="text-align: right">
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" width="100%" xmlns:asp="#unknown">
ShowFooter="True" BackColor="#CCCCCC" BorderColor="#999999" BorderWidth="3px"
CellPadding="4" CellSpacing="2" DataKeyNames="code" Style="color: #FFC080" ForeColor="Black"
OnRowCommand="doDelete">
<footerstyle backcolor="#666699">
<rowstyle backcolor="White">
<selectedrowstyle backcolor="#6699FF" font-bold="True" forecolor="White">
<pagerstyle backcolor="#284775" borderstyle="None" borderwidth="1px" font-size="13px">
ForeColor="White" Height="10px" HorizontalAlign="Center" VerticalAlign="Middle"
Wrap="True" />
<headerstyle backcolor="Black" forecolor="White" cssclass="text" font-bold="True">
Wrap="True" />
<pagersettings visible="true">
<columns> <%--شماره--%>
<asp:templatefield headertext="کد تدریس">
<footertemplate>
<asp:literal id="lit" runat="server">
<itemtemplate>
<asp:literal id="lit_number" runat="server" text="<%# eval(" code")="" %>"="">
<itemstyle backcolor="#CCCCFF" forecolor="Black">
<%--شماره--%>
<%--نام--%>
<asp:templatefield headertext="کد تدریس">
<edititemtemplate>
<asp:textbox id="edit_name" runat="server" text="<%# Bind(" tadrisname")="" %>"="" height="20px">
Width="88px">
<footertemplate>
<asp:textbox id="txt_name" runat="server" width="86px" height="20px">
<itemtemplate>
<%#Eval("tadrisName")%>
<itemstyle backcolor="#CCCCFF" forecolor="Black">
<%--نام--%>
<%-- دكمه هاي انصراف وویرایش --%>
<asp:commandfield buttontype="Button" canceltext="انصراف" edittext="ویرایش" showeditbutton="True">
UpdateText="ویرایش" HeaderText="ویرایش">
<controlstyle backcolor="#CCCCFF" font-names="Tahoma" font-size="X-Small" forecolor="Black">
BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" />
<itemstyle cssclass="header_grid" forecolor="Black">
<%-- حذف --%>
<asp:templatefield headertext="حذف" showheader="False" itemstyle-forecolor="#DEDFDE">
<itemtemplate>
<asp:button id="btnRemove" runat="server" causesvalidation="False" commandname="Delete">
Text="حذف" OnClientClick="return confirm('?آیا مایل به حذف این پست هستید');" />
<controlstyle backcolor="#CCCCFF" bordercolor="Black" borderstyle="Solid" borderwidth="1px">
Font-Names="Tahoma" Font-Size="X-Small" ForeColor="Black" />
<itemstyle cssclass="header_grid" forecolor="Black">
<asp:templatefield headertext="حذف انتخابي" itemstyle-forecolor="#DEDFDE">
<footertemplate>
<asp:button commandname="Delete1" text="حذف" id="btnRemove1" runat="server" borderstyle="Solid">
OnClientClick="return confirmDelete();" BorderWidth="1px" BackColor="#DEDFDE"
Font-Names="Tahoma" Font-Size="11px" CssClass="menu" />
<itemtemplate>
<asp:checkbox id="ChkRemove" runat="server">
<itemstyle backcolor="#999999" horizontalalign="Center" bordercolor="White">
<headerstyle backcolor="Black" horizontalalign="Center">
<controlstyle backcolor="#9999FF" bordercolor="White" borderstyle="Solid" borderwidth="1px">
ForeColor="Red" />
<footerstyle backcolor="#999999" horizontalalign="Center">
<%--<asp:buttonfield buttontype="Button" commandname="btnselect" text="انتخاب" headertext="دکمه انتخاب ">--%>
|
--------------------------- source code asp.vb.net -----------------
--------------------------- source code asp.vb.net -----------------
--------------------------- source code asp.vb.net -----------------
Imports System.Web.Security
Imports System.Web.UI
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Imports System.Diagnostics
Imports System.IO
Imports System.Drawing
Imports System.Security.Cryptography
Partial Class TarifEtelaatForm
Inherits System.Web.UI.Page
Public name_tadris As String
Dim objConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("objConnect").ConnectionString)
Dim con As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("objConnect").ConnectionString)
Dim conS As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("objConnect").ConnectionString)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'If User.IsInRole("modir") = False Then
' Response.Redirect("DeFault.aspx")
' FormsAuthentication.SignOut()
'End If
If Not (User.Identity.IsAuthenticated) Then
'alert("You clicked me!");
'Response.Write("کاربر محترم شما باید قبلا ثبت نام کنید!'>")
Response.Redirect("DeFault.aspx")
Exit Sub
End If
'بررسی برای سطح دسترسی
'============================================================
Dim bank As LevelvorodDataContext = New LevelvorodDataContext
Dim Query = From T In bank.Table_Levels
Where (T.codeper = User.Identity.Name) _
Select T
Try
If Query.Count > 0 Then
For Each record In Query
If record.codeLevel > 1 Then
Response.Redirect("DeFault.aspx")
FormsAuthentication.SignOut()
End If
Next
End If
Catch ex As Exception
Finally
If (Not bank Is Nothing) Then bank.Connection.Close()
End Try
'=========================================================
If (User.Identity.IsAuthenticated) = True Then
Call MAxTadrisCode()
If Not IsPostBack Then
BindGridView()
BindGridViewSelect()
End If
End If
End Sub
Private Sub MAxTadrisCode()
Dim objMaxId As New SqlCommand
objConnection.Open()
objMaxId.Connection = objConnection
objMaxId.CommandText = "Select Max(code) From Table_tadrisName"
Dim MaxId As Object = objMaxId.ExecuteScalar()
If MaxId Is DBNull.Value Then
MaxId = 0
End If
TextBoxCode.Text = MaxId + 1
objMaxId.Cancel()
objConnection.Close()
End Sub
Private Sub dgBind()
Dim DS As New DataSet()
Dim objDataAdapter As New SqlDataAdapter( _
"Select code,tadrisName From Table_TadrisName Order By code Desc", objConnection)
objConnection.Open()
objDataAdapter.Fill(DS, "Table_TadrisName")
GridView1.DataSource = DS.Tables("Table_TadrisName")
GridView1.DataBind()
objConnection.Close()
End Sub
Private Sub MAxpostCode()
'بدست آوردن بزرگترین کد رکورداز جدول
Dim objMaxId As New SqlCommand
objConnection.Open()
objMaxId.Connection = objConnection
objMaxId.CommandText = "Select Max(code) From Table_TadrisName"
Dim MaxId As Object = objMaxId.ExecuteScalar()
If MaxId Is DBNull.Value Then
MaxId = 0
End If
TextBoxcode.Text = MaxId + 1
objMaxId.Cancel()
objConnection.Close()
'MaxId
End Sub
Public Sub BindGridView()
Dim Dta As SqlDataAdapter = Nothing
Dim Ds As DataSet
Dim com As New SqlCommand("select * from Table_TadrisName", con)
Try
Dta = New SqlDataAdapter(com)
Ds = New DataSet
Dta.Fill(Ds, "tadrisName")
GridView1.DataSource = Ds
GridView1.DataBind()
Finally
If (Not com Is Nothing) Then com.Dispose()
If (Not Dta Is Nothing) Then Dta.Dispose()
End Try
End Sub
Public Sub BindGridViewSelect()
Dim DtaS As SqlDataAdapter = Nothing
Dim DsS As DataSet
Dim comS As New SqlCommand("select * from Table_TadrisName ", conS)
Try
DtaS = New SqlDataAdapter(comS)
DsS = New DataSet
DtaS.Fill(DsS, "tadrisName")
GridView1.DataSource = DsS
GridView1.DataBind()
Finally
If (Not comS Is Nothing) Then comS.Dispose()
If (Not DtaS Is Nothing) Then DtaS.Dispose()
End Try
End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
Try
If e.CommandName = "sabt" Then
Dim str_name As String
'Dim str_family As String
'Dim str_city As String
Dim rowFooter As GridViewRow = GridView1.FooterRow
str_name = CType(rowFooter.FindControl("txt_name"), TextBox).Text
Dim bank1 As DataClassesTadrisDataContext = New DataClassesTadrisDataContext
Dim Query = From T In bank1.Table_tadrisNames
Where (T.tadrisName = str_name) _
Select T
If Query.Count > 0 Then
Lblpm.Text = "این نام دوره تدریس قبلاایجاد شده است، خطا "
TextBoxTadrisName.Text = ""
Call MAxTadrisCode()
Else
Dim com As New SqlCommand
com.Connection = con
com.CommandText = "insert into Table_TadrisName values(@tadrisName)"
com.Parameters.AddWithValue("@tadrisName", str_name)
'com.Parameters.AddWithValue("@code", str_family)
'com.Parameters.AddWithValue("@tel", phon)
Try
con.Open()
com.ExecuteNonQuery()
Catch ex As SqlException
MsgBox("اطلاعات ورودی شما ناقص میباشد. خواهشمندیم کاملش کنید", MsgBoxStyle.DefaultButton1, "خطا")
Response.Write(ex.Message.ToString())
Finally
If con.State <> ConnectionState.Closed Then con.Close()
If (Not com Is Nothing) Then com.Dispose()
GridView1.EditIndex = -1
BindGridView()
End Try
End If
End If
Catch ex As Exception
Response.Write(ex.Message.ToString)
End Try
'selected Girid حالت انتخاب رديفي از گريد
If e.CommandName = "btnselect" Then
Try
Dim idx As Integer
idx = Convert.ToInt32(e.CommandArgument)
For i = 0 To 5
GridView1.Rows(idx).Cells(i).BackColor = System.Drawing.Color.LightSkyBlue
Next
GridView1.RowStyle.BorderColor = Color.Blue
'بدست اوردن شماره مربوط به رديف انتخاب شده'
Dim rowid As GridViewRow = GridView1.Rows(idx)
Dim int_number As Integer = CType(rowid.FindControl("lit_number"), Literal).Text
'''''''''''''''''''''''''''''''''''''''''''''''
'جستجو براي فيلدهاي ركورد انتخابي'
Dim My_DS As New DataSet
Dim cmdText As String = "SELECT * FROM Table_tadrsName where code =" & int_number & ""
Using sqlAdapter As New SqlDataAdapter(cmdText, ConfigurationManager.ConnectionStrings("objConnect").ConnectionString)
sqlAdapter.Fill(My_DS)
End Using
ReadDataTable_1(My_DS.Tables(0))
Catch ex As SqlException
Response.Redirect("Default.aspx")
Response.Write(ex.Message.ToString())
Finally
If conS.State <> ConnectionState.Closed Then conS.Close()
'If (Not comS Is Nothing) Then comS.Dispose()
BindGridView()
BindGridViewSelect()
End Try
End If
End Sub
Private Sub ReadDataTable_1(ByVal dtInput As DataTable)
' روال دستيابي به محتويات جدول با مورد خواسته شده
Dim sumResult As Long = 0
For Each row As DataRow In dtInput.Rows
TextBoxCode.Text = row("code").ToString
TextBoxTadrisName.Text = row("tadrsName").ToString
Response.Write("
موفق باشید")
'Response.Redirect("PostMashaghel.aspx")
Next
End Sub
Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim rowEdit As GridViewRow = GridView1.Rows(e.RowIndex)
Dim com As New SqlCommand
GridView1.ShowFooter = True
GridView1.EditIndex = -1
Dim int_number As String = CType(rowEdit.FindControl("lit_number"), Literal).Text
'Dim str_aks As String = String.Empty
'con.Open()
'com.Connection = con
'com.CommandText = "select * from Table_tadrisName where code ='" & int_number & "'"
'Dim reader As SqlDataReader = com.ExecuteReader
'If reader.HasRows = True Then
' reader.Read()
' str_aks = (reader.GetString(1))
'End If
'con.Close()
Try
Dim edit_name As String
'Dim edit_family As String
edit_name = CType(rowEdit.FindControl("edit_name"), TextBox).Text
'Table_tadrisNames :جستجو از جدول
Dim bank1 As DataClassesTadrisDataContext = New DataClassesTadrisDataContext
Dim Query = From T In bank1.Table_tadrisNames
Where (T.tadrisName = edit_name) _
Select T
If Query.Count > 0 Then
Lblpm.Text = "این نام دوره تدریس قبلاایجاد شده است، خطا "
TextBoxTadrisName.Text = ""
Call MAxTadrisCode()
Else
'edit_family = CType(rowEdit.FindControl("edit_family"), TextBox).Text
'edit_city = CType(rowEdit.FindControl("edit_list"), DropDownList).SelectedItem.Text
com.Connection = con
com.CommandText = "update Table_tadrisName set tadrisName=@tadrisName where code= '" & int_number & "'"
com.Parameters.AddWithValue("tadrisName", edit_name)
'com.Parameters.AddWithValue("family", edit_family)
'com.Parameters.AddWithValue("tel", phon)
Try
con.Open()
com.ExecuteNonQuery()
Lblpm.Text = ""
Catch ex As SqlException
Response.Write(ex.Message.ToString())
Finally
If con.State <> ConnectionState.Closed Then con.Close()
If (Not com Is Nothing) Then com.Dispose()
GridView1.EditIndex = -1
BindGridView()
End Try
End If
Catch ex As Exception
Response.Write(ex.Message.ToString)
End Try
End Sub
Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
'If e.Row.RowType = DataControlRowType.Footer Then
If e.Row.RowType = ListItemType.Footer Then
Dim btnAdd As New Button
btnAdd.ID = "btnAdd"
btnAdd.Text = "اضافه"
btnAdd.CommandName = "sabt"
btnAdd.BorderStyle = BorderStyle.Solid
btnAdd.BorderWidth = New Unit(1, UnitType.Pixel)
btnAdd.BackColor = Color.FromArgb(Int32.Parse("6666FF", Globalization.NumberStyles.AllowHexSpecifier))
btnAdd.Attributes.Add("Style", "Font-Family:Tahoma; Font-Size:11px")
e.Row.Cells(3).Controls.Add(btnAdd)
'بدست آوردن آخرین شماره رکورد از بانک
Dim lit As Literal = e.Row.FindControl("lit")
con.Open()
Dim com As New SqlCommand
com.Connection = con
com.CommandText = "SELECT MAX(code) FROM Table_tadrisName"
Dim a1 As Object = com.ExecuteScalar, p As Integer
If a1.ToString <> "" Then
p = CType(a1, Integer) + 1
lit.Text = p
con.Close()
Else
p = 1
lit.Text = p
con.Close()
End If
'--------------------------------------------------------------
End If
If ((e.Row.RowType = DataControlRowType.DataRow) And (e.Row.RowState = DataControlRowState.Edit)) Or ((e.Row.RowType = DataControlRowType.DataRow) And (e.Row.RowState.ToString() = "Alternate, Edit")) Then
Dim cancelButton As Button = CType(e.Row.Cells(2).Controls(2), Button)
cancelButton.BackColor = Color.FromKnownColor(KnownColor.LightBlue)
cancelButton.BorderWidth = Unit.Pixel(1)
cancelButton.Attributes.Add("Style", "Font-Family:Tahoma; Font-Size:11px")
Dim updateButton As Button = CType(e.Row.Cells(2).Controls(0), Button)
updateButton.BackColor = Color.FromKnownColor(KnownColor.Green)
updateButton.BorderWidth = Unit.Pixel(1)
updateButton.Attributes.Add("Style", "Font-Family:Tahoma; Font-Size:11px")
End If
'If ((e.Row.RowType = DataControlRowType.DataRow) And (e.Row.RowState = DataControlRowState.Edit)) Or ((e.Row.RowType = DataControlRowType.DataRow)) Then
' ' دررديف اول گريد حذف انجام نشود= دكمه حذف كار نكند
' Dim delete As New Button
' delete = CType(e.Row.Cells(3).FindControl("btnRemove"), Button)
' If 0 = GridView1.Rows.Count Then
' delete.Enabled = False
' Else
' delete.Enabled = True
' End If
' ' از كار انداختن تيك چك باكس كه انجام نشود= چك باكس آن رديف كار نكند
' Dim ChkRemove As New CheckBox
' ChkRemove = CType(e.Row.Cells(4).FindControl("ChkRemove"), CheckBox)
' If 0 = GridView1.Rows.Count Then
' ChkRemove.Enabled = False
' Else
' ChkRemove.Enabled = True
' End If
'End If
' ====================================================================
' +... ايجاد دكمه حذف براي انتخابهاي چك باكسي
Dim btnRemove1 As New Button
btnRemove1.ID = "btnRemove1"
btnRemove1.Text = "حذف"
btnRemove1.CommandName = "Delete1"
btnRemove1.BorderStyle = BorderStyle.Solid
btnRemove1.BorderWidth = New Unit(1, UnitType.Pixel)
btnRemove1.Attributes.Add("Style", "Font-Family:Tahoma; Font-Size:11px")
'e.Row.Cells(3).Controls.Add(btnRemove1)
' + ...
' =====================================================================
End Sub
'ايجاد روالي چهت حذف در صورت تيك دارشدن چك باكسها ...
Sub doDelete(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
'=+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
If (e.CommandName = "Delete1") Then
Dim chkRemove As WebControls.CheckBox
Dim strIDs As String = ""
Dim boolCheck As Boolean = False
For Each gvRow As GridViewRow In GridView1.Rows
chkRemove = DirectCast(gvRow.FindControl("ChkRemove"), WebControls.CheckBox)
If chkRemove.Checked Then
boolCheck = True
strIDs += GridView1.DataKeys(gvRow.RowIndex).Value & ","
End If
Next
If boolCheck = True Then
Dim strSQL As String = "Delete from Table_tadrisName where code IN (" & strIDs.Substring(0, strIDs.LastIndexOf(",")) & ")"
Dim strConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings("objConnect").ConnectionString
Dim Cnn As New SqlConnection(strConnection)
Dim Cmd As New SqlCommand(strSQL, Cnn)
Try
Cnn.Open()
Cmd.ExecuteNonQuery()
Lblpm.Text = ""
Catch ex As SqlException
Response.Write(ex.Message.ToString())
Finally
If (Cmd IsNot Nothing) Then Cmd.Dispose()
If (Cnn.State <> ConnectionState.Closed) Then Cnn.Close()
BindGridView()
'BindGridView(IIf(ViewState("drpPagingIndex") IsNot Nothing, Convert.ToInt32(ViewState("drpPagingIndex")), 0), 5)
End Try
End If
End If
'=+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
'Dim Da As SqlDataAdapter
'Dim Ds As New DataSet
'Dim com As SqlCommand
'Dim edit_list As New DropDownList
'edit_list = CType(e.Row.Cells(4).FindControl("edit_list"), DropDownList)
'If ((e.Row.RowType = DataControlRowType.DataRow) And (e.Row.RowState = DataControlRowState.Edit)) Or ((e.Row.RowType = DataControlRowType.DataRow) And (e.Row.RowState.ToString() = "Alternate, Edit")) Then
' com = New SqlCommand("select * from shahr", con)
' Da = New SqlDataAdapter(com)
' Ds = New DataSet
' Da.Fill(Ds, "shahr")
' edit_list.DataSource = Ds.Tables(0).DefaultView
' edit_list.DataValueField = "city"
' edit_list.DataBind()
' edit_list.SelectedValue = Session("list")
'End If
'Dim dd_list As DropDownList
'dd_list = CType(e.Row.Cells(4).FindControl("list_shahr"), DropDownList)
'If e.Row.RowType = ListItemType.Footer Then
' com = New SqlCommand("select * from shahr", con)
' Da = New SqlDataAdapter(com)
' Ds = New DataSet
' Da.Fill(Ds, "shahr")
' dd_list.DataSource = Ds.Tables(0).DefaultView
' dd_list.DataValueField = "city"
' dd_list.DataBind()
'End If
If e.Row.RowType = DataControlRowType.Pager Then
e.Row.Attributes.Add("onClick", "ClickColor('" + e.Row.ClientID + "')")
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor = 'ff00ff'")
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor = 'blue'")
End If
End Sub
Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
GridView1.ShowFooter = True
GridView1.EditIndex = -1
BindGridView()
Call MAxTadrisCode()
End Sub
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
GridView1.ShowFooter = False
'Dim str_city As String = String.Empty
'str_city = CType(GridView1.Rows(e.NewEditIndex).Cells(5).Controls(0), DataBoundLiteralControl).Text.Trim
'Session("list") = String.Concat(str_city)
GridView1.EditIndex = e.NewEditIndex
BindGridView()
End Sub
Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Dim rowEdit As GridViewRow = GridView1.Rows(e.RowIndex)
Dim com As New SqlCommand
Dim int_number As String = CType(rowEdit.FindControl("lit_number"), Literal).Text
'Dim str_aks As String = String.Empty
'con.Open()
'com.Connection = con
'com.CommandText = "select * from Table_tadrisName where code ='" & int_number & "'"
'Dim reader As SqlDataReader = com.ExecuteReader
'If reader.HasRows = True Then
' reader.Read()
' str_aks = (reader.GetString(1))
'End If
'con.Close()
com.Connection = con
com.CommandText = "delete from Table_tadrisName where code= '" & int_number & "'"
Try
con.Open()
com.ExecuteNonQuery()
'System.IO.File.Delete(Server.MapPath(str_aks))
Catch ex As SqlException
Response.Write(ex.Message.ToString())
Finally
If con.State <> ConnectionState.Closed Then con.Close()
If (Not com Is Nothing) Then com.Dispose()
BindGridView()
End Try
End Sub
Protected Sub _TarifEtelaatForm_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
For Each gvRow As GridViewRow In GridView1.Rows
Dim ref_Chk As CheckBox = DirectCast(gvRow.FindControl("chkRemove"), CheckBox)
ClientScript.RegisterArrayDeclaration("chk_Array_cods", String.Concat("'", ref_Chk.ClientID, "'"))
Next
'If (GridView1.Rows.Count > 0) Then
' gridelement.Value = GridView1.FooterRow.Cells().Controls(1).ClientID & "," & GridView1.FooterRow.Cells(5).Controls(0).ClientID & "," & GridView1.HeaderRow.Cells(6).Controls(1).Controls(0).Controls(0).ClientID
'End If
End Sub
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
'Dim ID As Integer = GridView1.DataKeys(GridView1.SelectedIndex).Value
'Dim cmdText As String = "IF NOT EXISTS( SELECT * FROM Tbl_Girid_Select WHERE (ID=@ID) ) INSERT INTO tbl_Girid_Select SELECT * FROM girid WHERE (ID=@ID)"
'Using objConn As New SqlConnection(ConfigurationManager.ConnectionStrings("dbTestConnectionString").ConnectionString)
' Using objCmd As New SqlCommand(cmdText, objConn)
' objConn.Open()
' objCmd.Parameters.AddWithValue("@ID", ID)
' objCmd.ExecuteNonQuery()
' objConn.Close()
' End Using
'End Using
'GridView1.DataBind()
End Sub
'Protected Sub GridView2_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView2.RowDeleting
' Call MAxTadrisCode()
' 'If MsgBox("آيا مطمئن هستيد كه ميخواهيداين رکور راحذف كنيد" _
' ' , MsgBoxStyle.Question + MsgBoxStyle.YesNo + _
' ' MsgBoxStyle.MsgBoxRight, "موافقت باعمل حذف") = MsgBoxResult.Yes Then
' ' objConnection.Open()
' ' Dim objcommand As New SqlCommand
' ' objcommand.Connection = objConnection
' ' objcommand.CommandText = "Delete Table_TadrisName Where" & _
' ' " code=" & GridView2.Rows(e.RowIndex).Cells(2).Text
' ' objcommand.ExecuteNonQuery()
' ' objConnection.Close()
' ' dgBind()
' 'Else
' ' Exit Sub
' 'End If
' Dim rowEdit As GridViewRow = GridView2.Rows(e.RowIndex)
' Dim com As New SqlCommand
' Dim int_number As String = GridView2.Rows(e.RowIndex).Cells(2).Text
' Dim str_aks As String = String.Empty
' 'objConnection.Open()
' 'com.Connection = objConnection
' 'com.CommandText = "select * from Table_TadrisName where code ='" & int_number & "'"
' 'Dim reader As SqlDataReader = com.ExecuteReader
' 'If reader.HasRows = True Then
' ' reader.Read()
' ' str_aks = (reader.GetString(1))
' 'End If
' 'objConnection.Close()
' com.Connection = objConnection
' com.CommandText = "delete from Table_TadrisName where code ='" & int_number & "'"
' Try
' objConnection.Open()
' com.ExecuteNonQuery()
' 'System.IO.File.Delete(Server.MapPath(str_aks))
' Catch ex As SqlException
' Response.Write(ex.Message.ToString() & "خطا")
' Finally
' If objConnection.State <> ConnectionState.Closed Then objConnection.Close()
' If (Not com Is Nothing) Then com.Dispose()
' 'BindGridView()
' End Try
'End Sub
Protected Sub BtnSabt_Click(sender As Object, e As System.EventArgs) Handles BtnSabt.Click
If TextBoxTadrisName.Text = "" Then
Lblpm.Text = "کاربر محترم نام دوره تدریس باید تکمیل شود،خطا"
Else
'بدست آوردن بزرگترین کد رکورد از جدول
Dim objMaxId As New SqlCommand
objConnection.Open()
objMaxId.Connection = objConnection
objMaxId.CommandText = "Select Max(code) From Table_tadrisName"
Dim MaxId As Object = objMaxId.ExecuteScalar()
If MaxId Is DBNull.Value Then
MaxId = 0
End If
objMaxId.Cancel()
objConnection.Close()
'''''''''''''''''''''
'Table_tadrisNames :جستجو از جدول
Dim bank1 As DataClassesTadrisDataContext = New DataClassesTadrisDataContext
Dim Query = From T In bank1.Table_tadrisNames
Where (T.tadrisName = TextBoxTadrisName.Text) _
Select T
If Query.Count > 0 Then
Lblpm.Text = "این نام دوره تدریس قبلاایجاد شده است، خطا "
TextBoxTadrisName.Text = ""
Call MAxTadrisCode()
Else
Try
Dim bank As DataClassesTadrisDataContext = New DataClassesTadrisDataContext
Dim Table_tadris As New Table_tadrisName
Table_tadris.code = MaxId + 1
Table_tadris.tadrisName = TextBoxTadrisName.Text
bank.Table_tadrisNames.InsertOnSubmit(Table_tadris)
bank.SubmitChanges()
Lblpm.Text = "اطلاعات با موفقیت ثبت شد"
Catch ex As Exception
Lblpm.Text = "کاربر محترم مجددااقدام شود،اطلاعات با موفقیت ثبت نشد،خطا،"
Finally
'Lblpm.Text = ""
End Try
Response.Redirect("TarifEtelaatForm.aspx")
Call MAxTadrisCode()
End If
End If
'Dim objCommand As New SqlCommand
'Dim objMaxId As New SqlCommand
'objConnection.Open()
'objCommand.Connection = objConnection
'objCommand.CommandText = "Insert Into Table_tadrisName(code" & _
' ",tadrisName) Values(@code," & _
' "@tadrisName)"
'objMaxId.Connection = objConnection
'objMaxId.CommandText = "Select Max(code) From Table_tadrisName"
'objMaxId.Clone()
'Dim MaxId As Object = objMaxId.ExecuteScalar()
'If MaxId Is DBNull.Value Then
' MaxId = 0
'End If
'objConnection.Close()
'objCommand.Parameters.AddWithValue("@code", MaxId + 1)
'objCommand.Parameters.AddWithValue("@tadrisName", TextBoxTadrisName.Text)
''objCommand.Parameters.AddWithValue("@postdate", jc.WhatDay)
''objCommand.Parameters.AddWithValue("@posttime", Now.ToShortTimeString)
'objConnection.Open()
'objCommand.ExecuteNonQuery()
'Dim intResult As Integer = objCommand.ExecuteNonQuery()
'If intResult > 0 Then
' Lblpm.Text = "با موفقیت انجام شد"
'Else
' Lblpm.Text = "خطا ! مجددا اقدام شود"
'End If
'objConnection.Close()
'' بازیابی مجدد جدول
'Dim DS As New DataSet()
'objConnection.Open()
'Dim objDataAdapter As New SqlDataAdapter( _
'"Select code,tadrisName From Table_TadrisName Order By code Desc", objConnection)
'objDataAdapter.Fill(DS, "Table_TadrisName")
'GridView2.DataSource = DS.Tables("Table_TadrisName")
'GridView2.DataBind()
'objConnection.Close()
'Dim RowEdit As Integer = Application("RowEdit").ToString
'Dim objCommand As New SqlCommand
'objCommand.Connection = objConnection
'objCommand.CommandText = "Update Table_TadrisName Set code='" & TextBoxCode.Text & "',tadrisName='" & TextBoxTadrisName.Text & "' Where code=" & TextBoxCode.Text
'objConnection.Open()
'objCommand.ExecuteNonQuery()
'objConnection.Close()
'dgBind()
'Response.Redirect("previouspost.aspx")
End Sub
Protected Sub Page_Unload(sender As Object, e As System.EventArgs) Handles Me.Unload
'FormsAuthentication.SignOut()
End Sub
Protected Sub BtnShow_Click(sender As Object, e As System.EventArgs) Handles BtnShow.Click
Response.Redirect("LoginModir.aspx")
'Call MAxTadrisCode()
End Sub
End Class
<big><small></small></big>