Grid Footer Button Save/
Upadate/Delete/Cancel/Exit--HTML
<%@PageLanguage="VB"AutoEventWireup="false"CodeFile="AdresscontactMaster.aspx.vb"Inherits="AdresscontactMaster"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD
XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<scripttype="text/javascript">
function confirmation() {
if (confirm('are you
sure you want to delete ?')) {
returntrue;
}else{
returnfalse;
}
}
</script>
<title>New Row save update delete
cancel</title>
</head>
<body>
<formid="form1"runat="server">
<divstyle="background-color:
#ffffcc">
<tableid="Table1"style="background-color:lemonchiffon
">
<tr>
<tdcolspan="2"style="height: 44px">
<spanstyle="font-size: 32pt"> <span
style="font-size: 24pt"> <spanstyle="color:
#3399ff">Address Contact Master</span></span></span></td>
</tr>
<tr>
<tdrowspan="2"style="width: 293px"valign="top">
<asp:GridViewID="GridView1"runat="server"CellPadding="4"ShowFooter="true"AutoGenerateColumns="false"ForeColor="#333333"GridLines="None"Height="170px">
<RowStyleBackColor="#FFFBD6"ForeColor="#333333"/>
<FooterStyleBackColor="#990000"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="#FFCC66"ForeColor="#333333"HorizontalAlign="Center"/>
<SelectedRowStyleBackColor="#FFCC66"Font-Bold="True"ForeColor="Navy"/>
<HeaderStyleBackColor="#990000"Font-Bold="True"ForeColor="White"/>
<AlternatingRowStyleBackColor="White"/>
<Columns>
<asp:TemplateFieldHeaderText="Firstname">
<ItemTemplate>
<asp:LinkButtonID="LinkButton1"CommandArgument='<%#Eval("ID") %>'OnCommand="GetValueonclick_Records"runat="server"><%#Eval("Firstname")
%></asp:LinkButton>
<asp:HiddenFieldID="RecId"Value='<%#Eval("ID") %>'runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Middlename">
<ItemTemplate>
<%#Eval("Middlename")
%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Middlename">
<ItemTemplate>
<%#Eval("Lastname")
%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
<tdstyle="width: 495px; height: 186px; background-color:
#ffffff;"valign="top">
<asp:gridviewID="Gridview2"runat="server"AutoGenerateColumns="False"ShowFooter="True"CellPadding="4"ForeColor="#333333"Width="124px">
<RowStyleBackColor="#E3EAEB"/>
<FooterStyleBackColor="#1C5E55"Font-Bold="True"ForeColor="White"/>
<PagerStyleBackColor="#666666"ForeColor="White"HorizontalAlign="Center"/>
<SelectedRowStyleBackColor="#C5BBAF"Font-Bold="True"ForeColor="#333333"/>
<HeaderStyleBackColor="#1C5E55"Font-Bold="True"ForeColor="White"/>
<EditRowStyleBackColor="#7C6F57"/>
<AlternatingRowStyleBackColor="White"/>
<Columns>
<asp:TemplateFieldHeaderText="New
Row"FooterText="New Row">
<ItemTemplate>
<asp:ImageButtonID="ImageButton2"OnClick="Imagebutton1_Click"runat="server"ImageUrl="~/scripts/tn_plus.GIF"/>
</ItemTemplate>
<FooterTemplate>
<%--<asp:Button ID="Button1" OnClick="ButtonNew_Click"
runat="server" Text="Button" />--%>
<asp:ButtonID="bNew"OnClick="ButtonNew_Click"runat="server"Text="New"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="FirstName">
<ItemTemplate>
<asp:TextBoxID="TextBox1"runat="server"Text='<%#Eval("Firstname") %>'></asp:TextBox>
<asp:HiddenFieldID="RecId"Value='<%#Eval("ID") %>'runat="server"/>
</ItemTemplate>
<FooterTemplate>
<asp:ButtonID="Save"OnClick="ButtonSave_Click"runat="server"Text="Save"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Middlename">
<ItemTemplate>
<asp:TextBoxID="TextBox2"runat="server"Text='<%#Eval("Middlename") %>'></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:ButtonID="Update"OnClick="ButtonUpdate_Click"runat="server"Text="Update"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Lastname">
<ItemTemplate>
<asp:TextBoxID="TextBox3"runat="server"Text='<%#Eval("Lastname") %>'></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:ButtonID="delete"runat="server"CommandArgument='<%#Eval("Id") %>'oncommand="delete_Records"onclientclick="return
confirm('Do you want to delete this record?');"Text="Delete"/>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
</ItemTemplate>
<FooterTemplate>
<asp:ButtonID="Exit1"OnClick="ButtonExit_Click"runat="server"Text="Cancel"/>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:gridview>
</td>
</tr>
<tr>
<tdstyle="width: 495px; height:
205px">
</td>
</tr>
<tr>
<tdcolspan="2">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
VbCode------
Imports System
ImportsSystem.Data
ImportsSystem.Data.SqlClient
ImportsSystem.Configuration
ImportsSystem.Web
ImportsSystem.Web.Security
ImportsSystem.Web.UI
ImportsSystem.Web.UI.WebControls
ImportsSystem.Web.UI.WebControls.WebParts
ImportsSystem.Web.UI.HtmlControls
PartialClassAdresscontactMaster
InheritsSystem.Web.UI.Page
DimoblGFAsNewGlovalFunction
DimobjrunAsNewruntimetable
DimModeStatusAsString
ProtectedSubPage_Load(ByVal sender AsObject,
ByVal e AsSystem.EventArgs) HandlesMe.Load
Try
IfNotPage.IsPostBackThen
DimdrAsDataRow = Nothing
OneRowuploadsingrid()
binddataGrid3()
' getValue()
HandelControls("V")
EndIf
Catch ex AsException
EndTry
EndSub
PrivateSubOneRowuploadsingrid()
Try
objrun.InitAdressContacttable()
ViewState("CurrentTable") = objrun.dtaddressDetail
objrun.dtaddressDetail.Rows(0).Item("ID") = 1
objrun.dtaddressDetail.Rows(0).Item("Firstname") = String.Empty
objrun.dtaddressDetail.Rows(0).Item("Middlename") = String.Empty
objrun.dtaddressDetail.Rows(0).Item("Lastname") = String.Empty
Gridview2.DataSource =
objrun.dtaddressDetail
Gridview2.DataBind()
Catch ex AsException
EndTry
EndSub
PrivateSubbinddataGrid3()
Dim ds AsNewDataSet
ds =
oblGF.selectdataforregtableforaddress()
GridView1.DataSource = ds
GridView1.DataBind()
EndSub
PrivateSubAddNewRowToGrid()
DimrowIndexAsInteger
= 0
IfViewState("CurrentTable")
IsNotNothingThen
DimdtCurrentTableAsDataTable = DirectCast(ViewState("CurrentTable"), DataTable)
'dtCurrentTable.Rows.Add(dtCurrentTable.NewRow)
DimdrCurrentRowAsDataRow = Nothing
IfdtCurrentTable.Rows.Count> 0 Then
For i AsInteger = 1
TodtCurrentTable.Rows.Count
Dim box1 AsTextBox = DirectCast(Gridview2.Rows(rowIndex).Cells(0).FindControl("TextBox1"), TextBox)
Dim box2 AsTextBox = DirectCast(Gridview2.Rows(rowIndex).Cells(1).FindControl("TextBox2"), TextBox)
Dim box3 AsTextBox = DirectCast(Gridview2.Rows(rowIndex).Cells(2).FindControl("TextBox3"), TextBox)
drCurrentRow
= dtCurrentTable.NewRow()
drCurrentRow("ID") = i + 1
dtCurrentTable.Rows(i
- 1)("FirstName") = box1.Text
dtCurrentTable.Rows(i
- 1)("Middlename") = box2.Text
dtCurrentTable.Rows(i
- 1)("Lastname") = box3.Text
rowIndex
+= 1
Next
dtCurrentTable.Rows.Add(drCurrentRow)
ViewState("CurrentTable") = dtCurrentTable
Gridview2.DataSource =
dtCurrentTable
Gridview2.DataBind()
EndIf
Else
Response.Write("ViewState is null")
EndIf
SetPreviousData()
EndSub
PrivateSubSetPreviousData()
DimrowIndexAsInteger
= 0
IfViewState("CurrentTable")
IsNotNothingThen
DimdtAsDataTable = DirectCast(ViewState("CurrentTable"), DataTable)
Ifdt.Rows.Count> 0 Then
For i AsInteger = 0
Todt.Rows.Count - 1
Dim box1 AsTextBox = DirectCast(Gridview2.Rows(rowIndex).Cells(0).FindControl("TextBox1"), TextBox)
Dim box2 AsTextBox = DirectCast(Gridview2.Rows(rowIndex).Cells(1).FindControl("TextBox2"), TextBox)
Dim box3 AsTextBox = DirectCast(Gridview2.Rows(rowIndex).Cells(2).FindControl("TextBox3"), TextBox)
box1.Text = dt.Rows(i)("FirstName").ToString()
box2.Text = dt.Rows(i)("Middlename").ToString()
box3.Text = dt.Rows(i)("Lastname").ToString()
rowIndex
+= 1
Next
EndIf
EndIf
EndSub
ProtectedSubButtonSave_Click(ByVal sender AsObject,
ByVal e AsEventArgs)
Try
putvalue()
objrun.saveAddressmaster()
' ScriptManager.RegisterStartupScript(Me, Me.[GetType](),
"key", "alert('Record Has been
Save Successfully');", True)
HandelControls("M")
clear()
binddataGrid3()
Catch ex AsException
EndTry
EndSub
ProtectedSubButtonUpdate_Click(ByVal sender AsObject,
ByVal e AsEventArgs)
Try
'Dim id As Integer =
CInt(Page.Request.QueryString("Id"))
'If id > 0 Then
DimrowIndexAsInteger
= 0
Dim Rid AsHiddenField = DirectCast(GridView1.Rows(rowIndex).Cells(0).FindControl("RecId"), HiddenField)
putvalue()
objrun.UpdateAddressMaster(Rid.Value)
'ScriptManager.RegisterStartupScript(Me, Me.[GetType](),
"key", "alert('Record Has been
Updated Successfully');", True)
'End If
binddataGrid3()
Catch ex AsException
EndTry
EndSub
'Protected Sub Buttondelete_Click(ByVal sender As Object, ByVal e
As CommandEventArgs)
' Try
' Dim str As String =
e.CommandArgument.ToString
' Dim id As Integer =
CInt(str)
' 'Dim id As Integer
= CInt(Page.Request.QueryString("Id"))
' 'If id > 0 Then
'
objrun.deletreAddressmaster(id)
' clear()
' 'End If
' binddataGrid3()
' Catch ex As Exception
' End Try
'End Sub
ProtectedSubdelete_Records(ByVal sender AsObject,
ByVal e AsCommandEventArgs)
Try
DimrowIndexAsInteger
= 0
Dim Rid AsHiddenField = DirectCast(GridView1.Rows(rowIndex).Cells(0).FindControl("RecId"), HiddenField)
objrun.deletreAddressmaster(Rid.Value)
clear()
binddataGrid3()
Catch ex AsException
EndTry
EndSub
ProtectedSubButtonNew_Click(ByVal sender AsObject,
ByVal e AsEventArgs)
Try
HandelControls("A")
clear()
Catch ex AsException
EndTry
EndSub
ProtectedSubButtonExit_Click(ByVal sender AsObject,
ByVal e AsEventArgs)
Try
'clear()
OneRowuploadsingrid()
HandelControls("V")
Catch ex AsException
EndTry
EndSub
PrivateSubputvalue()
DimrowIndexAsInteger
= 0
objrun.InitAdressContacttable()
objrun.dtaddressDetail.Rows.Clear()
Dim i AsInteger = 0
For i = 0 To
Gridview2.Rows.Count - 1
Dim box1 AsTextBox = DirectCast(Gridview2.Rows(i).Cells(0).FindControl("TextBox1"), TextBox)
Dim box2 AsTextBox = DirectCast(Gridview2.Rows(i).Cells(1).FindControl("TextBox2"), TextBox)
Dim box3 AsTextBox = DirectCast(Gridview2.Rows(i).Cells(2).FindControl("TextBox3"), TextBox)
objrun.dtaddressDetail.Rows.Add(objrun.dtaddressDetail.NewRow)
Withobjrun.dtaddressDetail.Rows(i)
.Item("Firstname")
= box1.Text
.Item("Middlename")
= box2.Text
.Item("Lastname")
= box3.Text
EndWith
Next
EndSub
ProtectedSubGetValueonclick_Records(ByVal sender AsObject,
ByVal e AsCommandEventArgs)
Try
objrun.InitAdressContacttable()
objrun.dtaddressDetail.Rows.Clear()
DimstrAsString =
e.CommandArgument.ToString
Dim id AsInteger = CInt(str)
DimdtAsNewSystem.Data.DataTable
dt =
oblGF.getdataForaddress(id)
Dim box1 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(0).FindControl("TextBox1"), TextBox)
Dim box2 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(1).FindControl("TextBox2"), TextBox)
Dim box3 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(2).FindControl("TextBox3"), TextBox)
box1.Text = dt.Rows(0)("Firstname").ToString()
box2.Text = dt.Rows(0)("Middlename").ToString()
box3.Text = dt.Rows(0)("Lastname").ToString()
objrun.dtaddressDetail.Rows.Add(objrun.dtaddressDetail.NewRow)
Withobjrun.dtaddressDetail.Rows(0)
.Item("Firstname")
= box1.Text
.Item("Middlename")
= box2.Text
.Item("Lastname")
= box3.Text
EndWith
HandelControls("M")
Catch ex AsException
EndTry
EndSub
'Private Sub getValue(ByVal e As CommandEventArgs)
' Try
' 'Dim id As Integer
= CInt(Page.Request.QueryString("Id"))
' 'If id > 0 Then
' 'ByVal e
AsCommandEventArgs
' Dim str As String =
e.CommandArgument.ToString
' Dim id As Integer =
CInt(str)
' Dim dtAs New
System.Data.DataTable
' dt = oblGF.getdataForaddress(id)
' Dim box1 As TextBox
= DirectCast(Gridview2.Rows(0).Cells(0).FindControl("TextBox1"),
TextBox)
' Dim box2 As TextBox
= DirectCast(Gridview2.Rows(0).Cells(1).FindControl("TextBox2"),
TextBox)
' Dim box3 As TextBox
= DirectCast(Gridview2.Rows(0).Cells(2).FindControl("TextBox3"),
TextBox)
' box1.Text =
dt.Rows(0)("Firstname").ToString()
' box2.Text =
dt.Rows(0)("Middlename").ToString()
' box3.Text =
dt.Rows(0)("Lastname").ToString()
' With objrun.dtaddressDetail.Rows(0)
'
.Item("Firstname") = box1.Text
'
.Item("Middlename") = box2.Text
'
.Item("Lastname") = box3.Text
' End With
' 'End If
' Catch ex As Exception
' End Try
'End Sub
PrivateSubclear()
OneRowuploadsingrid()
'Dim box1 As TextBox =
DirectCast(Gridview2.Rows(0).Cells(0).FindControl("TextBox1"),
TextBox)
'Dim box2 As TextBox =
DirectCast(Gridview2.Rows(0).Cells(1).FindControl("TextBox2"),
TextBox)
'Dim box3 As TextBox = DirectCast(Gridview2.Rows(0).Cells(2).FindControl("TextBox3"),
TextBox)
'box1.Text = ""
'box2.Text = ""
'box3.Text = ""
EndSub
PrivateSubHandelControls(ByValStrStatusAsString)
Try
ModeStatus
= StrStatus
SelectCaseStrStatus
Case"A"
DimbNewAsButton = DirectCast(Gridview2.FooterRow.FindControl("bNew"), Button)
Dim Save AsButton = DirectCast(Gridview2.FooterRow.FindControl("Save"), Button)
Dim Update AsButton = DirectCast(Gridview2.FooterRow.FindControl("Update"), Button)
Dim delete AsButton = DirectCast(Gridview2.FooterRow.FindControl("delete"), Button)
DimExitRecordAsButton = DirectCast(Gridview2.FooterRow.FindControl("Exit1"), Button)
bNew.Text
= "New"
Save.Text
= "Save"
Update.Text
= "Update"
delete.Text
= "delete"
ExitRecord.Text
= "Cancel"
bNew.Enabled
= False
Save.Enabled
= True
Update.Enabled
= False
delete.Enabled
= False
ExitRecord.Enabled
= True
UNLockCtrl()
Case"M"
DimbNewAsButton = DirectCast(Gridview2.FooterRow.FindControl("bNew"), Button)
Dim Save AsButton = DirectCast(Gridview2.FooterRow.FindControl("Save"), Button)
Dim Update AsButton = DirectCast(Gridview2.FooterRow.FindControl("Update"), Button)
Dim delete AsButton = DirectCast(Gridview2.FooterRow.FindControl("delete"), Button)
Dim Exit1 AsButton = DirectCast(Gridview2.FooterRow.FindControl("Exit1"), Button)
bNew.Text
= "New"
Save.Text
= "Save"
Update.Text
= "Update"
delete.Text
= "delete"
Exit1.Text = "Cancel"
bNew.Enabled
= True
Save.Enabled
= False
Update.Enabled
= True
delete.Enabled
= True
Exit1.Enabled = True
UNLockCtrl()
Case"V"
DimbNewAsButton = DirectCast(Gridview2.FooterRow.FindControl("bNew"), Button)
Dim Save AsButton = DirectCast(Gridview2.FooterRow.FindControl("Save"), Button)
Dim Update AsButton = DirectCast(Gridview2.FooterRow.FindControl("Update"), Button)
Dim delete AsButton = DirectCast(Gridview2.FooterRow.FindControl("delete"), Button)
Dim Exit1 AsButton = DirectCast(Gridview2.FooterRow.FindControl("Exit1"), Button)
bNew.Text
= "New"
Save.Text
= "Save"
Update.Text
= "Update"
delete.Text
= "delete"
Exit1.Text = "Cancel"
bNew.Enabled
= True
Save.Enabled
= False
Update.Enabled
= False
delete.Enabled
= False
Exit1.Enabled = False
LockCtrl()
EndSelect
Catch ex AsException
EndTry
EndSub
PrivateSubLockCtrl()
Try
Dim box1 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(0).FindControl("TextBox1"), TextBox)
Dim box2 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(1).FindControl("TextBox2"), TextBox)
Dim box3 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(2).FindControl("TextBox3"), TextBox)
box1.Enabled = False
box2.Enabled = False
box3.Enabled = False
Catch ex AsException
EndTry
EndSub
PrivateSubUNLockCtrl()
Try
Dim box1 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(0).FindControl("TextBox1"), TextBox)
Dim box2 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(1).FindControl("TextBox2"), TextBox)
Dim box3 AsTextBox = DirectCast(Gridview2.Rows(0).Cells(2).FindControl("TextBox3"), TextBox)
box1.Enabled = True
box2.Enabled = True
box3.Enabled = True
Catch ex AsException
EndTry
EndSub
ProtectedSub Imagebutton1_Click(ByVal sender AsObject,
ByVal e AsSystem.Web.UI.ImageClickEventArgs)
Try
AddNewRowToGrid()
Catch ex AsException
EndTry
EndSub
EndClass
No comments:
Post a Comment