Have a fun while searching

Friday, December 24, 2010

In grid View find from one item template to other item template field data using row command

protected void GVCustomerPlan_RowCommand1(object sender, GridViewCommandEventArgs e)
{
if(e.commandname == "xyz")
{
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
Label lblProdId = (Label)row.FindControl("lblproductId");
}
}

Wednesday, July 21, 2010

function for sql

ALTER function [dbo].[GetRomanDate]
(
@Date datetime
)
returns varchar(20)
Begin
Declare @RomanDate varchar(20)
select @RomanDate=Convert(varchar(8),@Date,4)+ ' - '+ Convert(varchar(8),@Date,108)
return @RomanDate
End
--------------------------------
ALTER function [dbo].[GetperiodTitle](@Periodid int)
returns varchar(500)
as
begin
declare @title varchar(500)
set @title=(select 'Tema: ' + Periodname as periodname from utbfperiod where bfperiodid=@Periodid)
return @title

End
-------------------------------
ALTER function [dbo].[getCourseString]
(
@kindergarden varchar(100),@city varchar(100)
)
returns varchar(200)
begin
declare @TempString varchar(250)
set @TempString=''
if(@kindergarden=''and @city='')
begin
set @TempString=''
end
else
if(@kindergarden=''and @city <> '')
begin
set @TempString=@city
end
else if(@kindergarden <> '' and @city='')
begin
set @TempString=@kindergarden
end
else if(@kindergarden <>''and @city <> '')
begin
set @TempString=@kindergarden +', '+@city
end



return @TempString
end

tiggers for delete and update

ALTER trigger [dbo].[TRIG_StopDelete_UtBFDiscussion]
on [dbo].[UtBFDiscussion]
for delete as
begin
declare @num_Deleted int
/* Determine how many rows were deleted. */
select @num_Deleted = @@rowcount
if @num_Deleted > 1
Begin
select ' Invalid Operation'
rollback transaction
End
else
Begin
select str(@num_Deleted) + ' row(s) Deleted'
End
End
--------------------------
ALTER trigger [dbo].[TRIG_StopUpdate_UtBFDiscussion]
on [dbo].[UtBFDiscussion]
for update as
begin
declare @num_updated int
/* Determine how many rows were updated. */
select @num_updated = @@rowcount
if @num_updated > 1
Begin
select 'Invalid Operation'
rollback transaction
End
else
Begin
select str(@num_updated) + ' row(s) Updated'
End
End

Find Second Heighest salary

select top 1 t1.salary from
(select top 2 salary from dbo.tdemos order by salary desc)t1 order by salary asc

Thursday, February 11, 2010

This Look Codeeing


-----------------------
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;

public partial class Assignment : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
try
{
BtnSubmit.Attributes.Add("OnClick", "return validateSubmit();");
txtEmailid.Attributes.Add("OnChange", "return validateEmail();");
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("Slno", typeof(Int32));
dt.Columns.Add("BusnessName", typeof(string));
dt.Columns.Add("Password", typeof(string));
dt.Columns.Add("CheckBox", typeof(string));
dt.Columns.Add("ContactName", typeof(string));
dt.Columns.Add("Country", typeof(string));
dt.Columns.Add("State", typeof(string));
dt.Columns.Add("District", typeof(string));
dt.Columns.Add("City", typeof(string));
dt.Columns.Add("email", typeof(string));
dt.Columns.Add("Address", typeof(string));
dt.Columns.Add("pincode", typeof(string));
dt.Columns.Add("PhoneNumber", typeof(string));
dt.Clear();
if (Session["Datatable"] != null)
{
Session.Remove("Datatable");
}
Session["Datatable"] = dt;
}
}
catch (Exception ex)
{
throw(ex);
}
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
try
{
DataTable dt= (DataTable)Session["Datatable"];
Int32 slno = 0;
if (dt != null)
{
if (dt.Rows.Count > 0)
{
DataView dv = new DataView(dt);
dv.RowFilter = "Slno = Max(Slno)";
slno = Convert.ToInt32(dv[0][0]);
}
if (txtBusinessName.Text.Trim() != "")
{
DataRow dr = dt.NewRow();
dr[0] = Convert.ToInt32(slno + 1);
dr[1] = Convert.ToString(txtBusinessName.Text.Trim());
dr[2] = Convert.ToString(txtPassword.Text);
if (CheckBoxShow.Checked == true)
{
dr[3] = Convert.ToString("Y");
}
else
{
dr[3] = Convert.ToString("N");
}
dr[4] = Convert.ToString(TxtContactPerson.Text);
dr[5] = Convert.ToString(ddlCountry.SelectedItem);
dr[6] = Convert.ToString(ddlState.SelectedItem);
dr[7] = Convert.ToString(ddlDistrict.SelectedItem);
dr[8] = Convert.ToString(ddlCity.SelectedItem);
dr[9] = Convert.ToString(txtEmailid.Text);
dr[10] = Convert.ToString(txtAddress.Text);
dr[11] = Convert.ToString(txtPincode.Text);
dr[12] = Convert.ToString(txtContactNo.Text);
dt.Rows.Add(dr);
Session["Datatable"] = dt;
Gview.DataSource = dt;
Gview.DataBind();
UpdGview.Update();
txtBusinessName.Text = "";
TxtContactPerson.Text = "";
txtPassword.Text = "";
CheckBoxShow.Checked = false;
ddlCountry.SelectedValue = "Select";
ddlState.SelectedValue = "Select";
ddlDistrict.SelectedValue = "Select";
ddlCity.SelectedValue = "Select";
txtEmailid.Text = "";
txtAddress.Text = "";
txtPincode.Text = "";
txtContactNo.Text = "";
UpdLblBusinessName.Update();
UpdlblContactPerson.Update();
UpdtxtPassword.Update();
UpdddlCountry.Update();
UpdddlState.Update();
UpdddlDistrict.Update();
UpdddlCity.Update();
UpdtxtEmailid.Update();
UpdtxtAddress.Update();
UpdtxtPincode.Update();
UpdtxtContactNo.Update();
}
}
}
catch (Exception ex)
{
throw (ex);
}
}
protected void Gview_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
GridView InnerGridView = (GridView)e.CommandSource;
if (e.CommandName == "Select1")
{
Label lblslno = new Label();
lblslno = (Label)InnerGridView.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("LblSlno");
DataTable dt=(DataTable)Session["Datatable"];
DataView dv = new DataView(dt);
dv.RowFilter = "Slno = '" + Convert.ToInt32(lblslno.Text.Trim()) + "'";
if (dv.Count > 0)
{
txtBusinessName.Text = Convert.ToString(dv[0][1]);
txtPassword.Text = Convert.ToString(dv[0][2]);
TxtContactPerson.Text = Convert.ToString(dv[0][4]);
if (Convert.ToString(dv[0][3]) == "Y")
{
CheckBoxShow.Checked = true;
}
else
{
CheckBoxShow.Checked = false;
}
ddlCountry.SelectedValue = Convert.ToString(dv[0][5]);
ddlState.SelectedValue = Convert.ToString(dv[0][6]);
ddlDistrict.SelectedValue = Convert.ToString(dv[0][7]);
ddlCity.SelectedValue = Convert.ToString(dv[0][8]);
txtEmailid.Text = Convert.ToString(dv[0][9]);
txtAddress.Text = Convert.ToString(dv[0][10]);
txtPincode.Text = Convert.ToString(dv[0][11]);
txtContactNo.Text = Convert.ToString(dv[0][12]);
UpdLblBusinessName.Update();
UpdlblContactPerson.Update();
UpdtxtPassword.Update();
UpdddlCountry.Update();
UpdddlState.Update();
UpdddlDistrict.Update();
UpdddlCity.Update();
UpdtxtEmailid.Update();
UpdtxtAddress.Update();
UpdtxtPincode.Update();
UpdtxtContactNo.Update();
}
}
else if (e.CommandName == "Select2")
{
Label lblslno = new Label();
lblslno = (Label)InnerGridView.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("LblSlno");
Deletes(Convert.ToInt32(lblslno.Text));
}
}
catch (Exception ex)
{
throw (ex);
}
}
private void Deletes(Int32 lblslno)
{
try
{
DataTable dt = (DataTable)Session["Datatable"];
DataView dv = new DataView(dt);
dv.RowFilter = "Slno <> '" + Convert.ToInt32(lblslno) + "'";
DataTable dt1 = dv.ToTable("dt1");
Session["Datatable"] = dt1;
if (Session["Datatable"] != null)
{
Gview.DataSource = (DataTable)Session["Datatable"];
Gview.DataBind();
UpdGview.Update();
}
}
catch (Exception ex)
{
throw (ex);
}
}
protected void BtnDelete_Click(object sender, EventArgs e)
{
try
{
DataTable dt = (DataTable)Session["Datatable"];
foreach (GridViewRow gvr in Gview.Rows)
{
CheckBox chkbox = (CheckBox)gvr.FindControl("chkItems");
if (chkbox.Checked == true)
{
Label lblslno = new Label();

lblslno = (Label)gvr.FindControl("LblSlno");
Deletes(Convert.ToInt32(lblslno.Text));
}
}
}
catch (Exception ex)
{
throw(ex);
}
}
public DataTable GetById(string id)
{
try
{
DataTable dt = (DataTable)Session["Datatable"];
DataView dv = dt.DefaultView;

dv.RowFilter = "BusnessName LIKE '" + id + "'";
if (dv.Count > 0)
{
LblMessage.Text = "";
dt = dv.ToTable("dt");
}
else
{
Response.Write("No Record Found By Starting Business Name with " + Session["Id"].ToString() );
LblMessage.Text = "No Record Found By Starting Business Name with " + Session["Id"].ToString();
GetById("%");
}
UpdLblMessage.Update();
return dt;
}
catch (Exception ex)
{
throw (ex);
}
}
protected void A_Click(object sender, EventArgs e)
{
try
{
string id = ((LinkButton)sender).ID.ToString()+"%";
if (Session["Id"] != null)
{
Session.Remove("Id");
}
Session["Id"] = id;
if (id != "All%")
{
Gview.DataSource = GetById(id);
}
else
{
Gview.DataSource = GetById("%");
}
Gview.DataBind();
UpdGview.Update();
}
catch (Exception ex)
{
throw (ex);
}
}
protected void Gview_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
Gview.PageIndex = e.NewPageIndex;
string id = null;
if (Session["Id"] != null)
{
id =Convert.ToString(Session["Id"]);
Gview.DataSource = GetById(id);
}
else
{
id = "%";
Gview.DataSource = GetById(id);
}
Gview.DataBind();
UpdGview.Update();
}
catch (Exception ex)
{
throw (ex);
}
}
}

--------------------------java script
// JScript File
function trim(str)
{
return str.replace(/^\s+|\s+$/g,"");
}
function validateEmail()
{
var emailField=document.getElementById("txtEmailid");
emailpat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}|(com|net|org|edu|mil|gov|arpa|biz|aero|name|coop|info|pro|museum))$/;
if( !emailpat.test( emailField.value ) )
{
alert('Please Enter Valid Email Id');
emailField.focus();
emailField.select();
return false;
}
return true;
}
function validateSubmit()
{
var txtBusinessName=document.getElementById("txtBusinessName");
var txtPassword=document.getElementById("txtPassword");
var TxtContactPerson=document.getElementById("TxtContactPerson");
var ddlCountry=document.getElementById("ddlCountry");
var ddlState=document.getElementById("ddlState");
var ddlDistrict=document.getElementById("ddlDistrict");
var ddlCity=document.getElementById("ddlCity");
var txtEmailid=document.getElementById("txtEmailid");
var txtAddress=document.getElementById("txtAddress");
var txtPincode=document.getElementById("txtPincode");
var txtContactNo=document.getElementById("txtPincode");
if(trim(txtBusinessName.value)=='')
{
alert('Please Provide Business Name');
txtBusinessName.focus();
return false;
}
if(trim(txtPassword.value)=='')
{
alert('Please Provide Password');
txtPassword.focus();
return false;
}
if(trim(TxtContactPerson.value)=='')
{
alert('Please Provide Contact Person');
TxtContactPerson.focus();
return false;
}
if(trim(ddlCountry.value)=='Select')
{
alert('Please Select Country');
ddlCountry.focus();
return false;
}
if(trim(ddlState.value)=='Select')
{
alert('Please Select State');
ddlState.focus();
return false;
}
if(trim(ddlDistrict.value)=='Select')
{
alert('Please Select District');
ddlDistrict.focus();
return false;
}
if(trim(ddlCity.value)=='Select')
{
alert('Please Select City');
ddlCity.focus();
return false;
}
if(trim(txtEmailid.value)=='')
{
alert('Please Provide Email ID');
txtEmailid.focus();
return false;

}
if(trim(txtAddress.value)=='')
{
alert('Please Provide Address');
txtAddress.focus();
return false;

}
if(trim(txtPincode.value)=='')
{
alert('Please Provide Pincode');
txtPincode.focus();
return false;

}
if(trim(txtContactNo.value)=='')
{
alert('Please Provide Contact No');
txtContactNo.focus();
return false;

}
}
function SelectAllCheckboxes(spanChk)
{

// Added as ASPX uses SPAN for checkbox

var oItem = spanChk.children;
var theBox= (spanChk.type=="checkbox") ?
spanChk : spanChk.children.item[0];
xState=theBox.checked;

elm=theBox.form.elements;
for(i=0;i if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
if(elm[i].checked!=xState)
elm[i].click();
}
}

how to design this Page


-------------
<%@ Page Language="C#" EnableSessionState="True" AutoEventWireup="true" CodeFile="Assignment.aspx.cs" Inherits="Assignment" %>

<!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>Assignment Page</title>
</head>
<script language="javascript" type="text/javascript" src="JavaScript/Assignment.js"></script>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div>
<fieldset>
<legend style="color:Blue;">Add New Client</legend>
<table cellspacing="0" cellpadding="3">
<tr>
<td style="width:15%" align="right">
<b><asp:Label ID="LblBusinessName" runat="server" Text="Business Name"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label2" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:30%;" align="left">
<asp:UpdatePanel ID="UpdLblBusinessName" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtBusinessName" runat="server" Width="150px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:15%" align="right">
<b><asp:Label ID="LblPassword" runat="server" Text="Password"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label3" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:20%" align="left">
<asp:UpdatePanel ID="UpdtxtPassword" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="150px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:10%" align="left">
<asp:UpdatePanel ID="UpdCheckBox" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:CheckBox ID="CheckBoxShow" runat="server" Text="Show/Hide" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="width:15%" align="right">
<b><asp:Label ID="lblContactPerson" runat="server" Text="Contact Person"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label4" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:30%;" align="left">
<asp:UpdatePanel ID="UpdlblContactPerson" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="TxtContactPerson" runat="server" Width="150px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:15%" align="right">
<b><asp:Label ID="LblCountry" runat="server" Text="Country"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label6" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:20%" align="left">
<asp:UpdatePanel ID="UpdddlCountry" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlCountry" runat="server" Width="180px">
<asp:ListItem Text="Choose the Country" Value="Select" Selected="True"></asp:ListItem>
<asp:ListItem Text="ACountry" Value="ACountry"></asp:ListItem>
<asp:ListItem Text="BCountry" Value="BCountry"></asp:ListItem>
<asp:ListItem Text="CCountry" Value="CCountry"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:10%" align="left">
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<b><asp:Label ID="Label1" runat="server" Text=" "></asp:Label></b>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="width:15%" align="right">
<b><asp:Label ID="lblState" runat="server" Text="State"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label8" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:30%;" align="left">
<asp:UpdatePanel ID="UpdddlState" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlState" runat="server" Width="180px">
<asp:ListItem Text="Choose the State" Value="Select" Selected="True"></asp:ListItem>
<asp:ListItem Text="AState" Value="AState"></asp:ListItem>
<asp:ListItem Text="BState" Value="BState"></asp:ListItem>
<asp:ListItem Text="CState" Value="CState"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:15%" align="right">
<b><asp:Label ID="lblDistrict" runat="server" Text="District"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label10" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:20%" align="left">
<asp:UpdatePanel ID="UpdddlDistrict" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlDistrict" runat="server" Width="180px">
<asp:ListItem Text="Choose the District" Value="Select" Selected="True"></asp:ListItem>
<asp:ListItem Text="ADistrict" Value="ADistrict"></asp:ListItem>
<asp:ListItem Text="BDistrict" Value="BDistrict"></asp:ListItem>
<asp:ListItem Text="CDistrict" Value="CDistrict"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:10%" align="left">
<asp:UpdatePanel ID="UpdatePanel6" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<b><asp:Label ID="Label5" runat="server" Text=" "></asp:Label></b>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="width:15%" align="right">
<b><asp:Label ID="lblCity" runat="server" Text="City"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label12" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:30%;" align="left">
<asp:UpdatePanel ID="UpdddlCity" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlCity" runat="server" Width="180px">
<asp:ListItem Text="Choose the City" Value="Select" Selected="True"></asp:ListItem>
<asp:ListItem Text="ACity" Value="ACity"></asp:ListItem>
<asp:ListItem Text="BCity" Value="BCity"></asp:ListItem>
<asp:ListItem Text="CCity" Value="CCity"></asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:15%" align="right">
<b><asp:Label ID="Label13" runat="server" Text="email Id"></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label14" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:20%" align="left">
<asp:UpdatePanel ID="UpdtxtEmailid" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtEmailid" runat="server" Width="150px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td style="width:10%" align="left">
<asp:UpdatePanel ID="UpdatePanel9" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<b><asp:Label ID="Label15" runat="server" Text=" "></asp:Label></b>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="width:100%" colspan="7">
<table width="100%" cellspacing="0" cellpadding="3">
<tr>
<td style="width:50%">
<table width="100%" cellspacing="0" cellpadding="0">
<tr>
<td style="width:30%" align="right" valign="top">
<b><asp:Label ID="lblAddress" runat="server" Text="Address"></asp:Label></b>
</td>
<td style="width:10%" align="center" valign="top">
<b><asp:Label ID="Label11" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:60%;" align="left" valign="top">
<asp:UpdatePanel ID="UpdtxtAddress" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Height="50px" Width="150px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</td>
<td style="width:50%">
<table width="100%" cellspacing="0" cellpadding="3">
<tr>
<td style="width:30%" align="right" valign="top">
<b><asp:Label ID="lblPincode" runat="server" Text="Pincode"></asp:Label></b>
</td>
<td style="width:10%" align="center" valign="top">
<b><asp:Label ID="Label19" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:60%;" align="left" valign="top">
<asp:UpdatePanel ID="UpdtxtPincode" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtPincode" runat="server" Width="150px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="width:30%" align="right" valign="top">
<b><asp:Label ID="lblContactNo" runat="server" Text="Contact No"></asp:Label></b>
</td>
<td style="width:10%" align="center" valign="top">
<b><asp:Label ID="Label21" runat="server" Text=":"></asp:Label></b>
</td>
<td style="width:60%;" align="left" valign="top">
<asp:UpdatePanel ID="UpdtxtContactNo" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:TextBox ID="txtContactNo" runat="server" Width="150px"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="width:15%" align="right">
<b><asp:Label ID="Label9" runat="server" Text=" "></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label16" runat="server" Text=" "></asp:Label></b>
</td>
<td style="width:30%;" align="left">
<b><asp:Label ID="Label24" runat="server" Text=" "></asp:Label></b>
</td>
<td style="width:15%" align="right">
<b><asp:Label ID="Label18" runat="server" Text=" "></asp:Label></b>
</td>
<td style="width:5%" align="center">
<b><asp:Label ID="Label22" runat="server" Text=" "></asp:Label></b>
</td>
<td style="width:20%" align="left">
<b><asp:Label ID="Label25" runat="server" Text=" "></asp:Label></b>
</td>
<td style="width:10%" align="right">
<asp:UpdatePanel ID="UpdatePanel10" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="BtnSubmit" runat="server" Text="Submit"
onclick="BtnSubmit_Click" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</fieldset>
</div>
<div style="text-align:right;vertical-align:middle;margin-top:10px;">
<asp:Button ID="BtnDelete" runat="server" Text="Delete Selected"
onclick="BtnDelete_Click" />
</div>
<div>
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td style="width:100%;" align="left">
<asp:LinkButton ID="All" ForeColor="Green" Font-Bold="true" runat="server" Text="All" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="A" ForeColor="Green" Font-Bold="true" runat="server"
Text="A" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="B" ForeColor="Green" Font-Bold="true" runat="server" Text="B" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="C" ForeColor="Green" Font-Bold="true" runat="server" Text="C" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="D" ForeColor="Green" Font-Bold="true" runat="server" Text="D" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="E" ForeColor="Green" Font-Bold="true" runat="server" Text="E" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="F" ForeColor="Green" Font-Bold="true" runat="server" Text="F" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="G" ForeColor="Green" Font-Bold="true" runat="server" Text="G" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="H" ForeColor="Green" Font-Bold="true" runat="server" Text="H" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="I" ForeColor="Green" Font-Bold="true" runat="server" Text="I" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="J" ForeColor="Green" Font-Bold="true" runat="server" Text="J" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="K" ForeColor="Green" Font-Bold="true" runat="server" Text="K" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="L" ForeColor="Green" Font-Bold="true" runat="server" Text="L" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="M" ForeColor="Green" Font-Bold="true" runat="server" Text="M" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="N" ForeColor="Green" Font-Bold="true" runat="server" Text="N" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="O" ForeColor="Green" Font-Bold="true" runat="server" Text="O" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="P" ForeColor="Green" Font-Bold="true" runat="server" Text="P" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="Q" ForeColor="Green" Font-Bold="true" runat="server" Text="Q" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="R" ForeColor="Green" Font-Bold="true" runat="server" Text="R" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="S" ForeColor="Green" Font-Bold="true" runat="server" Text="S" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="T" ForeColor="Green" Font-Bold="true" runat="server" Text="T" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="U" ForeColor="Green" Font-Bold="true" runat="server" Text="U" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="V" ForeColor="Green" Font-Bold="true" runat="server" Text="V" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="W" ForeColor="Green" Font-Bold="true" runat="server" Text="W" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="X" ForeColor="Green" Font-Bold="true" runat="server" Text="X" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="Y" ForeColor="Green" Font-Bold="true" runat="server" Text="Y" onclick="A_Click"></asp:LinkButton> | 
<asp:LinkButton ID="Z" ForeColor="Green" Font-Bold="true" runat="server" Text="Z" onclick="A_Click"></asp:LinkButton>
</td>
</tr>
<tr>
<td style="width:100%">
<asp:UpdatePanel ID="UpdLblMessage" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="LblMessage" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="width:100%">
<asp:UpdatePanel ID="UpdGview" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="Gview" runat="server" Width="100%" AllowPaging="true"
PagerSettings-Mode="Numeric" PagerSettings-Position="Top" PageSize="5"
AutoGenerateColumns="false" onrowcommand="Gview_RowCommand"
onpageindexchanging="Gview_PageIndexChanging">
<Columns>
<asp:TemplateField Visible="false" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="LblSlno" runat="server" Text='<%# Eval("Slno") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="3%">
<HeaderTemplate>
<input id="chkAll" runat="server" onclick="javascript:SelectAllCheckboxes(this);" type="checkbox" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkItems" runat="server"/>
</ItemTemplate>
<ItemStyle BackColor="#01CCCC" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Business Name<br/>Contact Person" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblNames" runat="server" Text='<%# Eval("BusnessName") %>' />
<br/>
<asp:Label ID="Label23" runat="server" Text="Mr." />
<asp:Label ID="lblContactName" runat="server" Text='<%# Eval("ContactName") %>' />
</ItemTemplate>
<ItemStyle BackColor="#01CCCC" />
</asp:TemplateField>
<asp:TemplateField HeaderText="City - District(State)<br/>Phone" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label ID="lblCity" runat="server" Text='<%# Eval("City") %>' />
<asp:Label ID="Label27" runat="server" Text=" - " />
<asp:Label ID="lblDistrict" runat="server" Text='<%# Eval("District") %>'/>
<asp:Label ID="Label29" runat="server" Text="(" />
<asp:Label ID="lblState" runat="server" Text='<%# Eval("State") %>' />
<asp:Label ID="Label31" runat="server" Text=")" />
<br/>
<asp:Label ID="lblphoneNumber" runat="server" Text='<%# Eval("PhoneNumber") %>' />
</ItemTemplate>
<ItemStyle BackColor="#01CCCC" />
</asp:TemplateField>
<asp:ButtonField ButtonType="Button" ItemStyle-BackColor="#01CCCC" CommandName="Select1" Text="Edit" Visible="true" ItemStyle-Width="5%"/>
<asp:ButtonField ButtonType="Button" ItemStyle-BackColor="#01CCCC" CommandName="Select2" Text="Delete" Visible="true" ItemStyle-Width="5%"/>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
-----------------cs file will be in second one

Saturday, February 6, 2010

Add Multiple row in grid aspx

>asp:gridview ID="Gridview1" runat="server" ShowFooter="true" AutoGenerateColumns="false" >
>Columns>
>asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
>asp:TemplateField HeaderText="Header 1">
>ItemTemplate>
>asp:TextBox ID="TextBox1" runat="server">
>/ItemTemplate>
>/asp:TemplateField>
>asp:TemplateField HeaderText="Header 2">
>ItemTemplate>
>asp:TextBox ID="TextBox2" runat="server">
>/ItemTemplate>
>/asp:TemplateField>
>asp:TemplateField HeaderText="Header 3">
>ItemTemplate>
>asp:TextBox ID="TextBox3" runat="server">
>/ItemTemplate>
>FooterStyle HorizontalAlign="Right" />
>FooterTemplate>
>asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" OnClick="ButtonAdd_Click"/>
>/FooterTemplate>
>/asp:TemplateField>
>/Columns>
>/asp:gridview>

Add Multiple row in griw aspx code

\
\
\
\
\
\
\

\
\
\
\
\

\
\
\
\\
\

\
\
\
\

\
\

\

Add Column Dynamicaly in Grid View On Click On new Button


-----------------Code (cs)---------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetInitialRow();
}
}
private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Column1", typeof(string)));
dt.Columns.Add(new DataColumn("Column2", typeof(string)));
dt.Columns.Add(new DataColumn("Column3", typeof(string)));
dr = dt.NewRow();
dr["RowNumber"] = 1;
dr["Column1"] = string.Empty;
dr["Column2"] = string.Empty;
dr["Column3"] = string.Empty;
dt.Rows.Add(dr);
//dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
Gridview1.DataSource = dt;
Gridview1.DataBind();
}
private void AddNewRowToGrid()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
//extract the TextBox values
TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["RowNumber"] = i + 1;
drCurrentRow["Column1"] = box1.Text;
drCurrentRow["Column2"] = box2.Text;
drCurrentRow["Column3"] = box3.Text;
rowIndex++;
}
//add new row to DataTable
dtCurrentTable.Rows.Add(drCurrentRow);
//Store the current data to ViewState
ViewState["CurrentTable"] = dtCurrentTable;
//Rebind the Grid with the current data
Gridview1.DataSource = dtCurrentTable;
Gridview1.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
}
private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 1; i < dt.Rows.Count; i++)
{
TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3");
box1.Text = dt.Rows[i]["Column1"].ToString();
box2.Text = dt.Rows[i]["Column2"].ToString();
box3.Text = dt.Rows[i]["Column3"].ToString();
rowIndex++;
}
}
}
}
protected void ButtonAdd_Click(object sender, EventArgs e)
{
AddNewRowToGrid();
}
---------------Aspx code-------------------------
























--------o/p-----------------------

Friday, February 5, 2010

Create Output Parameter in sql and axis in another sp

//create outpur parameter
ALTER proc [dbo].[UDPTimeTableDateTimeVenueVerify1]
(
@fYear numeric(18,0),
@fSlNo numeric(18,0) OUTPUT
)
as
begin
select @fSlNo=fSlNo
from tMasterTimeTable
where fYear=@fYear
end
-------------------------------------------------

//axis output parameter
DECLARE @fSlNo1 Int
exec UDPTimeTableDateTimeVenueVerify1 2009,@fSlNo = @fSlNo1 output
select @fSlNo1 as 'fslno'

To Get Multiple row of one column in single row

ALTER proc [dbo].[UDPAssignmentNotSubmittedSubjectList]
(
@fYear numeric(18,0),
@fStream_ID nvarchar(100),
@fCourse_ID nvarchar(100)
)
as
begin
create table #_tmp_table (fEnrolmentNo nvarchar(100),fYear numeric(18,0),fStudent_Name nvarchar(100),fStream_ID nvarchar(100),fCourse_ID nvarchar(100),
TotalSubjects nvarchar(100),AssignmentGiven nvarchar(100))
insert into #_tmp_table
select temp.fEnrolmentNo,temp.fYear,temp.fStudent_Name,temp.fStream_ID, temp.fCourse_ID,
temp.fSubject_ID as 'TotalSubjects',tetmp1.fAssignmentStatus as 'AssignmentGiven'
from
( select innertemp.fEnrolmentNo,innertemp.fStudent_Name,innertemp.fYear,innertemp.fStream_ID,innertemp.fCourse_Id,
innertemp.fSubject_ID
from
(select DISTINCT(tMasterStudentReg.fEnrollmentNo) as fEnrolmentNo ,tMasterStudentReg.fStudent_Name,
tMasterStudentReg.fYear,tMasterStudentReg.fStream_ID,
tMasterStudentSubjectReg.fCourse_Id,tMasterStudentSubjectReg.fSubject_ID
from tMasterStudentReg inner join tMasterStudentSubjectReg
on tMasterStudentReg.fEnrollmentNo=tMasterStudentSubjectReg.fEnrollmentNo
and tMasterStudentReg.fStream_ID=tMasterStudentSubjectReg.fStream_ID
where (tMasterStudentReg.fYear <= @fYear and tMasterStudentReg.fYear > (@fYear-3))
and tMasterStudentReg.fStream_ID=@fStream_ID
and tMasterStudentSubjectReg.fCourse_Id=@fCourse_Id)innertemp inner join
tMasterSubjectList
on innertemp.fStream_ID=tMasterSubjectList.fStream_ID
and innertemp.fCourse_Id=tMasterSubjectList.fCourse_Id
and innertemp.fSubject_ID=tMasterSubjectList.fSubject_ID
where tMasterSubjectList.fProject='N'
)temp
left outer join
(select fEnrolmentNo,fSubject_ID,fAssignmentStatus from tTransAssignment
where fAssignmentStatus='Y'
and tTransAssignment.fStream_ID= @fStream_ID
and tTransAssignment.fCourse_Id= @fCourse_ID
)tetmp1
on temp.fEnrolmentNo=tetmp1.fEnrolmentNo
and temp.fSubject_ID=tetmp1.fSubject_ID
where tetmp1.fAssignmentStatus is null
order by temp.fEnrolmentNo,temp.fSubject_ID

SELECT DISTINCT A.fStream_ID, A.fCourse_ID, A.AssignmentGiven,TotalSubjects1
FROM #_tmp_table A
CROSS APPLY
(
-- Now get all the articles for each author in XML
SELECT TotalSubjects + ', ' FROM #_tmp_table B WHERE A.fEnrolmentNo = B.fEnrolmentNo
FOR XML Path('')
) AS C (TotalSubjects1)
end


--exec UDPAssignmentNotSubmittedSubjectList 2009,'PGDBM','S2'

o/p-->
fStream_ID fCourse_ID AssignmentGiven TotalSubjects1
PGDBM S2 NULL DBM432, DBM433, DBM434,
PGDBM S2 NULL DBM421, DBM422, DBM428, DBM430, DBM435