Test.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MultirowEditing.aspx.cs"
Inherits="MultirowEditing" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<center>
<h4 style="color: Purple; font-family: Arial">
FLAT MASTER</h4>
</center>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<fieldset>
<legend>Select One</legend>
<table width="100%" cellspacing="0">
<tr>
<td colspan="3" style="text-align: center">
<span class="style7">Project Name
</span> <asp:DropDownList ID="ddlproject" runat="server" Width="243px" Font-Names="Arial"
OnSelectedIndexChanged="ddlproject_SelectedIndexChanged" AutoPostBack="true">
</asp:DropDownList>
<asp:Label ID="lblMsg" runat="server" Width="127px" Style="font-size: x-small; font-family: Arial, Helvetica, sans-serif"></asp:Label>
</td>
</tr>
</table>
</fieldset>
<br />
<center>
<asp:GridView ID="GridView1" runat="server" EmptyDataText="No Record" Style="text-align: center;
font-family: Arial, Helvetica, sans-serif; font-size: small; margin-left: 0px;"
DataKeyNames="FLATID" AutoGenerateColumns="False" Width="100%" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"
PageSize="15">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Select">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="true" Text="Select All"
OnCheckedChanged="CheckBox1_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="true" OnCheckedChanged="chkSelect_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="" SortExpression="FLATNO">
<ItemTemplate>
<asp:HiddenField ID="pid" Value='<%# Bind("FLATID") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FLATNO" SortExpression="FLATNO">
<EditItemTemplate>
<asp:TextBox ID="FLATNOED" runat="server" Text='<%# Bind("FLATNO") %>' Width="50px"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="FLATNOIT" runat="server" Text='<%# Bind("FLATNO") %>' Enabled="false" Width="50px"
ForeColor="Black"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BHK1" SortExpression="BHK1">
<EditItemTemplate>
<asp:RadioButton ID="BHK1ED" runat="server" Checked='<%# Bind("BHK1") %>' GroupName="a" />
</EditItemTemplate>
<ItemTemplate>
<asp:RadioButton ID="BHK1IT" runat="server" Checked='<%# Bind("BHK1") %>' Enabled="false"
GroupName="b" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BHK2" SortExpression="BHK2">
<EditItemTemplate>
<asp:RadioButton ID="BHK2ED" runat="server" Checked='<%# Bind("BHK2") %>' GroupName="a" />
</EditItemTemplate>
<ItemTemplate>
<asp:RadioButton ID="BHK2IT" runat="server" Checked='<%# Bind("BHK2") %>' Enabled="false"
GroupName="b" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BHK3" SortExpression="BHK3">
<EditItemTemplate>
<asp:RadioButton ID="BHK3ED" runat="server" Checked='<%# Bind("BHK3") %>' GroupName="a" />
</EditItemTemplate>
<ItemTemplate>
<asp:RadioButton ID="BHK3IT" runat="server" Checked='<%# Bind("BHK3") %>' Enabled="false"
GroupName="b" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BHK4" SortExpression="BHK4">
<EditItemTemplate>
<asp:RadioButton ID="BHK4ED" runat="server" Checked='<%# Bind("BHK4") %>' GroupName="a" />
</EditItemTemplate>
<ItemTemplate>
<asp:RadioButton ID="BHK4IT" runat="server" Checked='<%# Bind("BHK4") %>' Enabled="false"
GroupName="b" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VILLA" SortExpression="VILLA">
<EditItemTemplate>
<asp:RadioButton ID="VILLAED" runat="server" Checked='<%# Bind("VILLA") %>' GroupName="a" />
</EditItemTemplate>
<ItemTemplate>
<asp:RadioButton ID="VILLAIT" runat="server" Checked='<%# Bind("VILLA") %>' Enabled="false"
GroupName="b" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PREMIUM" SortExpression="PREMIUM">
<EditItemTemplate>
<asp:CheckBox ID="PREMIUMED" runat="server" Checked='<%# Bind("PREMIUM") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="PREMIUMIT" runat="server" Checked='<%# Bind("PREMIUM") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SERVENT" SortExpression="SERVENT">
<EditItemTemplate>
<asp:CheckBox ID="SERVENTED" runat="server" Checked='<%# Bind("SERVENT") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="SERVENTIT" runat="server" Checked='<%# Bind("SERVENT") %>' Enabled="false" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AREA" SortExpression="SIZE">
<EditItemTemplate>
<asp:TextBox ID="AREAED" runat="server" Text='<%# Bind("SIZE") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="AREAIT" runat="server" Text='<%# Bind("SIZE") %>' Enabled="false"
ForeColor="Black"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DIMENSION" SortExpression="SIZE">
<EditItemTemplate>
<asp:TextBox ID="DIMENSIONED" runat="server" Text='<%# Bind("DIMENSION") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="DIMENSIONIT" runat="server" Text='<%# Bind("DIMENSION") %>' Enabled="false"
ForeColor="Black"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="REMARKS" SortExpression="SIZE">
<EditItemTemplate>
<asp:TextBox ID="REMARKSED" runat="server" Text='<%# Bind("REMARKS") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="REMARKSIT" runat="server" Text='<%# Bind("REMARKS") %>' Enabled="false"
ForeColor="Black"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" Width="735PX" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
</center>
<asp:Button ID="Button1" runat="server" Text="All Update" OnClick="Button1_Click" />
</form>
</body>
</html>
Test.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using tally;
public partial class MultirowEditing : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ToString());
@base obj = new @base();
decimal Marea;
int ii;
int Mpid = 1;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
fillundergroup();
}
}
protected void ddlproject_SelectedIndexChanged(object sender, EventArgs e)
{
data();
}
public void fillundergroup()
{
try
{
string strDdl = "SELECT * from projectsite order by projectname ";
obj.FillDropdownListwithvalue(strDdl, ddlproject, "projectname", "projectcode");
}
catch { }
}
protected void data()
{
con.Close();
con.Open();
string ddl = ddlproject.SelectedValue;
String str = "SELECT [FlatId], [FLATNO], [BHK1], [BHK2], [BHK3], [BHK4],[VILLA], [PREMIUM], [SERVENT], [SIZE], [DIMENSION], [REMARKS] FROM [FLATDETAIL] where projectcode='" + ddl + "'";
SqlCommand com = new SqlCommand(str, con);
DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(com);
adp.Fill(ds, "f");
con.Close();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
data();
}
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
TextBox FLATNOIT = (TextBox)grdRow.FindControl("FLATNOIT");
RadioButton BHK1IT = (RadioButton)grdRow.FindControl("BHK1IT");
RadioButton BHK2IT = (RadioButton)grdRow.FindControl("BHK2IT");
RadioButton BHK3IT = (RadioButton)grdRow.FindControl("BHK3IT");
RadioButton BHK4IT = (RadioButton)grdRow.FindControl("BHK4IT");
RadioButton VILLAIT = (RadioButton)grdRow.FindControl("VILLAIT");
CheckBox SERVENTIT = (CheckBox)grdRow.FindControl("SERVENTIT");
CheckBox PREMIUMIT = (CheckBox)grdRow.FindControl("PREMIUMIT");
TextBox AREAIT = (TextBox)grdRow.FindControl("AREAIT");
TextBox DIMENSIONIT = (TextBox)grdRow.FindControl("DIMENSIONIT");
TextBox REMARKSIT = (TextBox)grdRow.FindControl("REMARKSIT");
if (chkTest.Checked)
{
FLATNOIT.Enabled = true;
FLATNOIT.ForeColor = System.Drawing.Color.Black;
BHK1IT.Enabled = true;
BHK1IT.ForeColor = System.Drawing.Color.Black;
BHK2IT.Enabled = true;
BHK2IT.ForeColor = System.Drawing.Color.Black;
BHK3IT.Enabled = true;
BHK3IT.ForeColor = System.Drawing.Color.Black;
BHK4IT.Enabled = true;
BHK4IT.ForeColor = System.Drawing.Color.Black;
VILLAIT.Enabled = true;
VILLAIT.ForeColor = System.Drawing.Color.Black;
SERVENTIT.Enabled = true;
SERVENTIT.ForeColor = System.Drawing.Color.Black;
PREMIUMIT.Enabled = true;
PREMIUMIT.ForeColor = System.Drawing.Color.Black;
AREAIT.Enabled = true;
AREAIT.ForeColor = System.Drawing.Color.Black;
DIMENSIONIT.Enabled = true;
DIMENSIONIT.ForeColor = System.Drawing.Color.Black;
REMARKSIT.Enabled = true;
REMARKSIT.ForeColor = System.Drawing.Color.Black;
}
else
{
FLATNOIT.Enabled = false;
FLATNOIT.ForeColor = System.Drawing.Color.Black;
BHK1IT.Enabled = false;
BHK1IT.ForeColor = System.Drawing.Color.Black;
BHK2IT.Enabled = false;
BHK2IT.ForeColor = System.Drawing.Color.Black;
BHK3IT.Enabled = false;
BHK3IT.ForeColor = System.Drawing.Color.Black;
BHK4IT.Enabled = false;
BHK4IT.ForeColor = System.Drawing.Color.Black;
VILLAIT.Enabled = false;
VILLAIT.ForeColor = System.Drawing.Color.Black;
SERVENTIT.Enabled = false;
SERVENTIT.ForeColor = System.Drawing.Color.Black;
PREMIUMIT.Enabled = false;
PREMIUMIT.ForeColor = System.Drawing.Color.Black;
AREAIT.Enabled = false;
AREAIT.ForeColor = System.Drawing.Color.Black;
DIMENSIONIT.Enabled = false;
DIMENSIONIT.ForeColor = System.Drawing.Color.Black;
REMARKSIT.Enabled = false;
REMARKSIT.ForeColor = System.Drawing.Color.Black;
}
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkSelectAll = sender as CheckBox;
chkSelectAll.Text = chkSelectAll.Checked ? "Deselect All" : "Select All";
foreach (GridViewRow grdRow in GridView1.Rows)
{
CheckBox chkSelect = grdRow.FindControl("chkSelect") as CheckBox;
if (chkSelect != null)
{
chkSelect.Checked = chkSelectAll.Checked;
TextBox FLATNOIT = (TextBox)grdRow.FindControl("FLATNOIT");
RadioButton BHK1IT = (RadioButton)grdRow.FindControl("BHK1IT");
RadioButton BHK2IT = (RadioButton)grdRow.FindControl("BHK2IT");
RadioButton BHK3IT = (RadioButton)grdRow.FindControl("BHK3IT");
RadioButton BHK4IT = (RadioButton)grdRow.FindControl("BHK4IT");
RadioButton VILLAIT = (RadioButton)grdRow.FindControl("VILLAIT");
CheckBox SERVENTIT = (CheckBox)grdRow.FindControl("SERVENTIT");
CheckBox PREMIUMIT = (CheckBox)grdRow.FindControl("PREMIUMIT");
TextBox AREAIT = (TextBox)grdRow.FindControl("AREAIT");
TextBox DIMENSIONIT = (TextBox)grdRow.FindControl("DIMENSIONIT");
TextBox REMARKSIT = (TextBox)grdRow.FindControl("REMARKSIT");
if (chkSelect.Checked)
{
FLATNOIT.Enabled = true;
FLATNOIT.ForeColor = System.Drawing.Color.Black;
BHK1IT.Enabled = true;
BHK1IT.ForeColor = System.Drawing.Color.Black;
BHK2IT.Enabled = true;
BHK2IT.ForeColor = System.Drawing.Color.Black;
BHK3IT.Enabled = true;
BHK3IT.ForeColor = System.Drawing.Color.Black;
BHK4IT.Enabled = true;
BHK4IT.ForeColor = System.Drawing.Color.Black;
VILLAIT.Enabled = true;
VILLAIT.ForeColor = System.Drawing.Color.Black;
SERVENTIT.Enabled = true;
SERVENTIT.ForeColor = System.Drawing.Color.Black;
PREMIUMIT.Enabled = true;
PREMIUMIT.ForeColor = System.Drawing.Color.Black;
AREAIT.Enabled = true;
AREAIT.ForeColor = System.Drawing.Color.Black;
DIMENSIONIT.Enabled = true;
DIMENSIONIT.ForeColor = System.Drawing.Color.Black;
REMARKSIT.Enabled = true;
REMARKSIT.ForeColor = System.Drawing.Color.Black;
}
else
{
FLATNOIT.Enabled = false;
FLATNOIT.ForeColor = System.Drawing.Color.Black;
BHK1IT.Enabled = false;
BHK1IT.ForeColor = System.Drawing.Color.Black;
BHK2IT.Enabled = false;
BHK2IT.ForeColor = System.Drawing.Color.Black;
BHK3IT.Enabled = false;
BHK3IT.ForeColor = System.Drawing.Color.Black;
BHK4IT.Enabled = false;
BHK4IT.ForeColor = System.Drawing.Color.Black;
VILLAIT.Enabled = false;
VILLAIT.ForeColor = System.Drawing.Color.Black;
SERVENTIT.Enabled = false;
SERVENTIT.ForeColor = System.Drawing.Color.Black;
PREMIUMIT.Enabled = false;
PREMIUMIT.ForeColor = System.Drawing.Color.Black;
AREAIT.Enabled = false;
AREAIT.ForeColor = System.Drawing.Color.Black;
DIMENSIONIT.Enabled = false;
DIMENSIONIT.ForeColor = System.Drawing.Color.Black;
REMARKSIT.Enabled = false;
REMARKSIT.ForeColor = System.Drawing.Color.Black;
}
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow grdRow in GridView1.Rows)
{
CheckBox chkSelect = grdRow.FindControl("chkSelect") as CheckBox;
HiddenField id = (HiddenField)grdRow.FindControl("pid");
TextBox FLATNOIT = (TextBox)grdRow.FindControl("FLATNOIT");
RadioButton BHK1IT = (RadioButton)grdRow.FindControl("BHK1IT");
RadioButton BHK2IT = (RadioButton)grdRow.FindControl("BHK2IT");
RadioButton BHK3IT = (RadioButton)grdRow.FindControl("BHK3IT");
RadioButton BHK4IT = (RadioButton)grdRow.FindControl("BHK4IT");
RadioButton VILLAIT = (RadioButton)grdRow.FindControl("VILLAIT");
CheckBox SERVENTIT = (CheckBox)grdRow.FindControl("SERVENTIT");
CheckBox PREMIUMIT = (CheckBox)grdRow.FindControl("PREMIUMIT");
TextBox AREAIT = (TextBox)grdRow.FindControl("AREAIT");
TextBox DIMENSIONIT = (TextBox)grdRow.FindControl("DIMENSIONIT");
TextBox REMARKSIT = (TextBox)grdRow.FindControl("REMARKSIT");
if (chkSelect.Checked)
{
string update = "update FLATDETAIL set FLATNO='" + FLATNOIT.Text + "', BHK1='" + BHK1IT.Checked + "',BHK2='" + BHK2IT.Checked + "',BHK3='" + BHK3IT.Checked + "',BHK4='" + BHK4IT.Checked + "',VILLA='" + VILLAIT.Checked + "',PREMIUM='" + PREMIUMIT.Checked + "',SERVENT='" + SERVENTIT.Checked + "', SIZE='" + AREAIT.Text + "',DIMENSION='" + DIMENSIONIT.Text + "',REMARKS='" + REMARKSIT.Text + "' where FLATID='" + id.Value + "' ";
bool sec = obj.ExecuteQuery(update);
}
}
data();
}
}
No comments :
Post a Comment