According Check Box On Grid View Delete The record Or change the Row color….
<%@PageLanguage="VB"AutoEventWireup="false"CodeFile="DeleteMultipleRecordFromGridandTransfertoanotherGrid.aspx.vb"Inherits="DeleteMultipleRecordFromGridandTransfertoanotherGrid"%>
<!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">
<title>Untitled Page</title>
<scripttype="text/javascript">
functionCheck_Click(obj)
{
var row =
obj.parentNode.parentNode;
if(obj.checked)
{
row.style.backgroundColor
= "aqua";
}
else
{
if(row.rowIndex % 2 == 0)
{
//Alternating Row Color
row.style.backgroundColor
= "#C2D69B";
}
else
{
row.style.backgroundColor
= "white";
}
}
varGridView = row.parentNode;
varinputList = GridView.getElementsByTagName("input");
for (var i=0;i<inputList.length;i++)
{
var cell
= inputList[i].parentNode;
varheaderCheckBox = inputList[0];
var checked = true;
if(inputList[i].type == "checkbox"&&inputList[i]
!= headerCheckBox)
{
if(!inputList[i].checked)
{
checked
= false;
break;
}
}
}
headerCheckBox.checked
= checked;
}
</script>
<scripttype="text/javascript">
functioncheckAll(objRef)
{
varGridView =
objRef.parentNode.parentNode.parentNode;
varinputList = GridView.getElementsByTagName("input");
for (var
i=0;i<inputList.length;i++)
{
//Get the Cell To find out ColumnIndex
var cell
= inputList[i].parentNode;
var row =
inputList[i].parentNode.parentNode;
if(inputList[i].type == "checkbox"&&cell.cellIndex
== 0 &&objRef != inputList[i])
{
if (objRef.checked)
{
row.style.backgroundColor
= "aqua";
inputList[i].checked=true;
}
else
{
if(row.rowIndex % 2 == 0)
{
//Alternating Row Color
row.style.backgroundColor
= "#C2D69B";
}
else
{
row.style.backgroundColor
= "white";
}
inputList[i].checked=false;
}
}
}
}
</script>
<scripttype="text/javascript">
functionMouseEvents(objRef, evt)
{
var checkbox = objRef.getElementsByTagName("input")[0];
if (evt.type == "mouseover")
{
objRef.style.backgroundColor
= "orange";
}
else
{
if (checkbox.checked)
{
objRef.style.backgroundColor
= "pink";
}
elseif(evt.type == "mouseout")
{
if(objRef.rowIndex % 2 == 0)
{
//Alternating Row Color
objRef.style.backgroundColor
= "#C2D69B";
}
else
{
objRef.style.backgroundColor
= "white";
}
}
}
}
</script>
</head>
<body>
<formid="form1"runat="server">
<div>
<table>
<tr>
<td>
<asp:LabelID="Label3"runat="server"Text="Check all
Using Javascipt"BackColor="#C0FFC0"Font-Bold="True"Width="355px"></asp:Label>
<asp:GridViewID="GridView1"runat="server"BackColor="White"OnRowDataBound="GridView1_RowDataBound"AutoGenerateColumns="false"BorderColor="#3366CC"BorderStyle="None"BorderWidth="1px"CellPadding="4"Width="89px">
<RowStyleBackColor="White"ForeColor="#003399"/>
<FooterStyleBackColor="#99CCCC"ForeColor="#003399"/>
<PagerStyleBackColor="#99CCCC"ForeColor="#003399"HorizontalAlign="Left"/>
<SelectedRowStyleBackColor="#009999"Font-Bold="True"ForeColor="#CCFF99"/>
<HeaderStyleBackColor="#003399"Font-Bold="True"ForeColor="#CCCCFF"/>
<Columns>
<asp:TemplateFieldHeaderText="Select">
<HeaderTemplate>
<asp:CheckBoxID="chkAll"runat="server"onclick="checkAll(this);"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBoxID="chkBox1"runat="server"onclick="Check_Click(this)">
</asp:CheckBox>
<asp:LabelID="lblId"runat="server"Text='<%#Eval("ID") %>'Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Si.NO">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundFieldDataField="Firstname"HeaderText="Firstname"/>
<asp:BoundFieldDataField="Middlename"HeaderText="Middlename"/>
<asp:BoundFieldDataField="Lastname"HeaderText="Lastname"/>
</Columns>
</asp:GridView>
</td>
<tdstyle="width: 3px">
<asp:LabelID="Label2"runat="server"Text="Check all
Using Without Javascipt"BackColor="#C0FFC0"Font-Bold="True"Width="348px"></asp:Label>
<asp:GridViewID="GridView3"runat="server"BackColor="White"OnRowDataBound="GridView3_RowDataBound"AutoGenerateColumns="false"BorderColor="#3366CC"BorderStyle="None"BorderWidth="1px"CellPadding="4"Width="89px">
<RowStyleBackColor="White"ForeColor="#003399"/>
<FooterStyleBackColor="#99CCCC"ForeColor="#003399"/>
<PagerStyleBackColor="#99CCCC"ForeColor="#003399"HorizontalAlign="Left"/>
<SelectedRowStyleBackColor="#009999"Font-Bold="True"ForeColor="#CCFF99"/>
<HeaderStyleBackColor="#003399"Font-Bold="True"ForeColor="#CCCCFF"/>
<Columns>
<asp:TemplateFieldHeaderText="Select">
<HeaderTemplate>
<asp:CheckBoxID="chkAll"runat="server"AutoPostBack="true"OnCheckedChanged="chkSelectAll_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBoxID="chkBox1"runat="server"AutoPostBack="true"OnCheckedChanged="chkSelectAll_CheckedChanged1">
</asp:CheckBox>
<asp:LabelID="lblId"runat="server"Text='<%#Eval("ID") %>'Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateFieldHeaderText="Si.NO">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundFieldDataField="Firstname"HeaderText="Firstname"/>
<asp:BoundFieldDataField="Middlename"HeaderText="Middlename"/>
<asp:BoundFieldDataField="Lastname"HeaderText="Lastname"/>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
<asp:LabelID="Label1"runat="server"Text="Label"></asp:Label>
<asp:ButtonID="BtnDelete"CausesValidation="false"OnClick="BtnDelete_Click"OnClientClick="return
confirm('Are you sure?')"runat="server"Text="Delete"/>
<asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Extract
Record"/>
<asp:GridViewID="GridView2"runat="server"CellPadding="4"AutoGenerateColumns="false"ForeColor="#333333"GridLines="None">
<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:BoundFieldDataField="Firstname"HeaderText="Firstname"/>
<asp:BoundFieldDataField="Middlename"HeaderText="Middlename"/>
<asp:BoundFieldDataField="Lastname"HeaderText="Lastname"/>
</Columns>
</asp:GridView>
</div>
</form>
</body>
</html>
Vb
Code::::----------------------------
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
PartialClassDeleteMultipleRecordFromGridandTransfertoanotherGrid
InheritsSystem.Web.UI.Page
DimoblGFAsNewGlovalFunction
DimobjrunAsNewruntimetable
ProtectedSubPage_Load(ByVal sender AsObject,
ByVal e AsSystem.EventArgs) HandlesMe.Load
IfNotPage.IsPostBackThen
binddataGrid3()
binddataGrid4()
EndIf
EndSub
PrivateSubbinddataGrid3()
Dim ds AsNewDataSet
ds =
oblGF.selectdataforregtableforaddress()
GridView1.DataSource = ds
GridView1.DataBind()
EndSub
PrivateSubbinddataGrid4()
Dim ds AsNewDataSet
ds =
oblGF.selectdataforregtableforaddress()
GridView3.DataSource = ds
GridView3.DataBind()
EndSub
ProtectedSubBtnDelete_Click(ByVal sender AsObject,
ByVal e AsSystem.EventArgs) HandlesBtnDelete.Click
Try
ForEach row AsGridViewRowIn
GridView1.Rows
DimcbAsCheckBox = DirectCast(row.FindControl("chkBox1"), CheckBox)
DimlblAsLabel = DirectCast(row.FindControl("lblId"), Label)
DimuidAsInteger = lbl.Text
Ifcb.CheckedThen
objrun.deletreAddressmaster(uid)
binddataGrid3()
EndIf
Next
Catch ex AsException
EndTry
EndSub
ProtectedSub Button1_Click(ByVal sender AsObject,
ByVal e AsSystem.EventArgs) Handles
Button1.Click
Try
Dim ds AsNewDataSet
DimdtAsNewDataTable
objrun.InitAdressContacttable()
objrun.dtaddressDetail.Rows.Clear()
Dim i AsInteger = 0
ForEach row AsGridViewRowIn
GridView1.Rows
DimcbAsCheckBox = DirectCast(row.FindControl("chkBox1"), CheckBox)
DimlblAsLabel = DirectCast(row.FindControl("lblId"), Label)
DimuidAsInteger =
lbl.Text
Ifcb.CheckedThen
dt =
objrun.ShowRegdata1(uid)
objrun.dtaddressDetail.Rows.Add(objrun.dtaddressDetail.NewRow)
objrun.dtaddressDetail.Rows(i)(0)
= dt.Rows(0).Item(0)
objrun.dtaddressDetail.Rows(i)(1)
= dt.Rows(0).Item(1)
objrun.dtaddressDetail.Rows(i)(2)
= dt.Rows(0).Item(2)
objrun.dtaddressDetail.Rows(i)(3)
= dt.Rows(0).Item(3)
i = i + 1
'GridView2.DataSource = objrun.dtaddressDetail
'GridView2.DataBind()
EndIf
Next
GridView2.DataSource =
objrun.dtaddressDetail
GridView2.DataBind()
Catch ex AsException
EndTry
EndSub
ProtectedSubchkSelectAll_CheckedChanged(ByVal sender AsObject,
ByVal e AsEventArgs)
ForEach row AsGridViewRowIn
GridView3.Rows
DimcbAsCheckBox = DirectCast(row.FindControl("chkBox1"), CheckBox)
cb.Checked
= DirectCast(sender, CheckBox).Checked
Ifcb.CheckedThen
row.BackColor
= Drawing.Color.BlanchedAlmond
Else
row.BackColor
= Drawing.Color.White
EndIf
Next
EndSub
ProtectedSubchkuncheck_CheckedChanged(ByVal sender AsObject,
ByVal e AsEventArgs)
Dim row AsGridViewRow = GridView3.SelectedRow
Dim i AsInteger =
GridView3.SelectedIndex
'For Each row As GridViewRowIn GridView3.Rows
DimcbAsCheckBox
cb =
DirectCast(row.FindControl("chkBox1"), CheckBox)
' cb.Checked =
DirectCast(sender, CheckBox).Checked
Ifcb.Checked = FalseThen
row.BackColor
= Drawing.Color.Blue
Else
row.BackColor
= Drawing.Color.Cyan
EndIf
'Next
EndSub
ProtectedSub GridView1_RowDataBound(ByVal sender AsObject,
ByVal e AsSystem.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound
Ife.Row.RowType = DataControlRowType.DataRowThen
e.Row.Attributes.Add("onmouseover", "MouseEvents(this,
event)")
e.Row.Attributes.Add("onmouseout", "MouseEvents(this,
event)")
EndIf
EndSub
'Protected Sub GridView3_SelectedIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles GridView3.SelectedIndexChanged
' Try
' For Each row As
GridViewRowIn GridView3.Rows
' Dim cb As
CheckBox = DirectCast(row.FindControl("chkBox1"), CheckBox)
' If cb.Checked
Then
'
row.BackColor = Drawing.Color.BlanchedAlmond
' Else
'
row.BackColor = Drawing.Color.Aqua
' End If
' Next
' Catch ex As Exception
' End Try
'End Sub
'Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As
GridViewCommandEventArgs)
' If e.CommandName =
"Show" Then
' Dim RowIndex1 As
Integer = Convert.ToInt32((e.CommandArgument).ToString())
' Dim cb As CheckBox
= DirectCast(RowIndex1.FindControl("chkBox1"), CheckBox)
' End If
'End Sub
ProtectedSub GridView3_RowDataBound(ByVal sender AsObject,
ByVal e AsSystem.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView3.RowDataBound
'Dim row As GridViewRow = e.Row
''Dim i As Integer = GridView3.SelectedIndex
''For Each row As GridViewRowIn GridView3.Rows
'Dim cb As CheckBox
'cb = DirectCast(row.FindControl("chkBox1"), CheckBox)
'' cb.Checked =
DirectCast(sender, CheckBox).Checked
'If cb.Checked = False Then
' row.BackColor =
Drawing.Color.Blue
'Else
' row.BackColor =
Drawing.Color.Cyan
'End If
Ife.Row.RowType = DataControlRowType.DataRowThen
If (String.IsNullOrEmpty(e.Row.Cells(0).Text)
<>True) OrElse
(e.Row.Cells(0).Text <>" ") Then
'Dim result As String = Convert.ToInt32(e.Row.Cells(2).Text)
'If result = "M.S" Then
e.Row.Cells(0).BackColor
= System.Drawing.Color.Aquamarine
'Else
'
e.Row.Cells(3).BackColor = System.Drawing.Color.BlanchedAlmond
'End If
EndIf
EndIf
EndSub
ProtectedSub
chkSelectAll_CheckedChanged1(ByVal sender AsObject, ByVal e AsEventArgs)
Try
ForEach row AsGridViewRowIn
GridView3.Rows
DimcbAsCheckBox = DirectCast(row.FindControl("chkBox1"), CheckBox)
' cb.Checked = DirectCast(sender, CheckBox).Checked
Ifcb.CheckedThen
row.BackColor
= Drawing.Color.BlanchedAlmond
Else
row.BackColor
= Drawing.Color.Yellow
EndIf
Next
Catch ex AsException
EndTry
EndSub
'Protected Sub GridView3_RowCommand(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles
GridView3.RowCommand
' Try
' Dim index As
Integer = Convert.ToInt32(e.CommandArgument)
' Dim gvRow As
GridViewRow = GridView1.Rows(index)
' Catch ex As Exception
' End Try
'End Sub
EndClass
No comments:
Post a Comment