Default.aspx
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowediting="GridView1_RowEditing">
<Columns>
<asp:BoundField DataField ="id" HeaderText ="id" ReadOnly="true" />
<asp:TemplateField HeaderText ="name">
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%#Eval("name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please enter the data" ControlToValidate ="TextBox1"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText ="fathername">
<ItemTemplate >
<asp:Label ID="Label2" runat="server" Text='<%#Eval("fathername") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("fathername") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Please enter the data" ControlToValidate ="TextBox2" ></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindDataToGrid();
}
}
public DataSet BindDataToGrid()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
SqlCommand cmd = new SqlCommand("select * from employee", con); SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
return ds;
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindDataToGrid();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindDataToGrid();
}
Thursday, January 28, 2010
Thursday, January 21, 2010
SharePoint Sites and workspaces
SharePoint Save site as template
Wednesday, January 20, 2010
SharePoint Tree view
SharePoint Title, description, and icon
Saturday, January 16, 2010
Create sharepoint Custom List and ContentType
SqlServer Substring
DECLARE @strString VARCHAR(50)
SET @strString = 'SUBSTRING'
SELECT SUBSTRING(@strString,1,1) AS STRSTRING
Result:S
SELECT SUBSTRING(@strString,1,2) AS STRSTRING
Result:SU
SELECT SUBSTRING(@strString,1,3) AS STRSTRING
Result:SUB
SELECT SUBSTRING(@strString,1,4) AS STRSTRING
Result:SUBS
SELECT SUBSTRING(@strString,1,5) AS STRSTRING
Result:SUBST
SELECT SUBSTRING(@strString,1,6) AS STRSTRING
Result:SUBSTR
SELECT SUBSTRING(@strString,1,7) AS STRSTRING
Result:SUBSTRI
SELECT SUBSTRING(@strString,1,8) AS STRSTRING
Result:SUBSTRIN
SELECT SUBSTRING(@strString,1,9) AS STRSTRING
Result:SUBSTRING
SELECT SUBSTRING(@strString,3,9) AS STRSTRING
Result:BSTRING
SELECT SUBSTRING(@strString,-5,9) AS STRSTRING
Result: SUB
SELECT SUBSTRING(@strString,-7,9) AS STRSTRING
Result:S
SET @strString = 'SUBSTRING'
SELECT SUBSTRING(@strString,1,1) AS STRSTRING
Result:S
SELECT SUBSTRING(@strString,1,2) AS STRSTRING
Result:SU
SELECT SUBSTRING(@strString,1,3) AS STRSTRING
Result:SUB
SELECT SUBSTRING(@strString,1,4) AS STRSTRING
Result:SUBS
SELECT SUBSTRING(@strString,1,5) AS STRSTRING
Result:SUBST
SELECT SUBSTRING(@strString,1,6) AS STRSTRING
Result:SUBSTR
SELECT SUBSTRING(@strString,1,7) AS STRSTRING
Result:SUBSTRI
SELECT SUBSTRING(@strString,1,8) AS STRSTRING
Result:SUBSTRIN
SELECT SUBSTRING(@strString,1,9) AS STRSTRING
Result:SUBSTRING
SELECT SUBSTRING(@strString,3,9) AS STRSTRING
Result:BSTRING
SELECT SUBSTRING(@strString,-5,9) AS STRSTRING
Result: SUB
SELECT SUBSTRING(@strString,-7,9) AS STRSTRING
Result:S
SqlServer Date Format
declare @startdate datetime
set @startdate='01-01-2009'
2) SELECT CONVERT(VARCHAR, startdate, 1)
from emp
Result: 01/01/09
3)SELECT CONVERT(VARCHAR, startdate, 2)
from emp
Result:09.09.09
4)SELECT CONVERT(VARCHAR, startdate, 3)
from emp
Result: 01/01/09
5)SELECT CONVERT(VARCHAR, startdate, 4)
from emp
Result: 01.01.09
6)SELECT CONVERT(VARCHAR, startdate, 5)
from emp
Result: 01-01-09
7)SELECT CONVERT(VARCHAR, startdate, 6)
from emp
Result: 01 Jan 0
8)SELECT CONVERT(VARCHAR, startdate, 7)
from emp
Result: Jan 01,
9)SELECT CONVERT(VARCHAR, startdate, 8)
from emp
Result: 00:00:00
10)SELECT CONVERT(VARCHAR, startdate, 9)
from emp
Result: Jan 1 2009 12:00:00:000AM
11)SELECT CONVERT(VARCHAR, startdate, 10)
from emp
Result: 01-01-09
12)SELECT CONVERT(VARCHAR, startdate, 11)
from emp
Result: 09/01/01
13)SELECT CONVERT(VARCHAR, startdate, 12)
from emp
Result: 090101
14)SELECT CONVERT(VARCHAR, startdate, 101)
from emp
Result: 01/01/2009
15)SELECT CONVERT(VARCHAR, startdate, 102)
from emp
Result: 2009.01.01
16)SELECT CONVERT(VARCHAR, startdate, 103)
from emp
Result: 09.01.01
17)SELECT CONVERT(VARCHAR, startdate, 104)
from emp
Result: 01/01/2009
18)SELECT CONVERT(VARCHAR, startdate, 105)
from emp
Result: 01-01-2009
19)SELECT CONVERT(VARCHAR, startdate, 106)
from emp
Result: 01 Jan 2009
20)SELECT CONVERT(VARCHAR, startdate, 107)
from emp
Result: Jan 01, 2009
21)SELECT CONVERT(VARCHAR, startdate, 108)
from emp
Result: 00:00:00
22)SELECT CONVERT(VARCHAR, startdate, 109)
from emp
Result: Jan 1 2009 12:00:00:000AM
23)SELECT CONVERT(VARCHAR, startdate, 110)
from emp
Result: 01-01-2009
24)SELECT CONVERT(VARCHAR, startdate, 111)
from emp
Result: 2009/01/01
set @startdate='01-01-2009'
2) SELECT CONVERT(VARCHAR, startdate, 1)
from emp
Result: 01/01/09
3)SELECT CONVERT(VARCHAR, startdate, 2)
from emp
Result:09.09.09
4)SELECT CONVERT(VARCHAR, startdate, 3)
from emp
Result: 01/01/09
5)SELECT CONVERT(VARCHAR, startdate, 4)
from emp
Result: 01.01.09
6)SELECT CONVERT(VARCHAR, startdate, 5)
from emp
Result: 01-01-09
7)SELECT CONVERT(VARCHAR, startdate, 6)
from emp
Result: 01 Jan 0
8)SELECT CONVERT(VARCHAR, startdate, 7)
from emp
Result: Jan 01,
9)SELECT CONVERT(VARCHAR, startdate, 8)
from emp
Result: 00:00:00
10)SELECT CONVERT(VARCHAR, startdate, 9)
from emp
Result: Jan 1 2009 12:00:00:000AM
11)SELECT CONVERT(VARCHAR, startdate, 10)
from emp
Result: 01-01-09
12)SELECT CONVERT(VARCHAR, startdate, 11)
from emp
Result: 09/01/01
13)SELECT CONVERT(VARCHAR, startdate, 12)
from emp
Result: 090101
14)SELECT CONVERT(VARCHAR, startdate, 101)
from emp
Result: 01/01/2009
15)SELECT CONVERT(VARCHAR, startdate, 102)
from emp
Result: 2009.01.01
16)SELECT CONVERT(VARCHAR, startdate, 103)
from emp
Result: 09.01.01
17)SELECT CONVERT(VARCHAR, startdate, 104)
from emp
Result: 01/01/2009
18)SELECT CONVERT(VARCHAR, startdate, 105)
from emp
Result: 01-01-2009
19)SELECT CONVERT(VARCHAR, startdate, 106)
from emp
Result: 01 Jan 2009
20)SELECT CONVERT(VARCHAR, startdate, 107)
from emp
Result: Jan 01, 2009
21)SELECT CONVERT(VARCHAR, startdate, 108)
from emp
Result: 00:00:00
22)SELECT CONVERT(VARCHAR, startdate, 109)
from emp
Result: Jan 1 2009 12:00:00:000AM
23)SELECT CONVERT(VARCHAR, startdate, 110)
from emp
Result: 01-01-2009
24)SELECT CONVERT(VARCHAR, startdate, 111)
from emp
Result: 2009/01/01
Monday, January 11, 2010
Gridview Sorting Asp.Net 2.0 and using up and down arrows
Deafault.aspx
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateColumns="False" onpageindexchanging="GridView1_PageIndexChanging"
onrowcreated="GridView1_RowCreated" onsorting="GridView1_Sorting">
<Columns>
<asp:BoundField DataField ="id" HeaderText ="id" SortExpression ="id" />
<asp:BoundField DataField ="name" HeaderText ="name" SortExpression ="name" />
<asp:BoundField DataField ="fathername" HeaderText ="fathername" SortExpression ="fathername" />
<asp:BoundField DataField ="designation" HeaderText ="designation" SortExpression ="designation" />
<asp:BoundField DataField ="address" HeaderText ="address" SortExpression ="address" />
</Columns>
</asp:GridView>
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["SortOrder"] = "DESC";
BindDataToGrid();
}
}
public DataSet BindDataToGrid()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
SqlCommand cmd = new SqlCommand("select * from employee", con); SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
return ds;
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.Header) {
int sortColumnIndex = GetSortColumnIndex();
if (sortColumnIndex != -1) {
AddSortImage(sortColumnIndex, e.Row);
}
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = FillGrid();
GridView1.DataBind();
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) {
ViewState["sortExpression"] = e.SortExpression;
if (ViewState["SortOrder"] != null) {
if (ViewState["SortOrder"].ToString().ToUpper() == "ASC")
{
ViewState["SortOrder"] = "DESC";
ViewState["SortDirection"] = SortDirection.Descending;
}
else
{
ViewState["SortOrder"] = "ASC";
ViewState["SortDirection"] = SortDirection.Ascending;
}
}
GridView1.PageIndex = 0;
GridView1.DataSource = FillGrid();
GridView1.DataBind();
}
private DataView FillGrid()
{
DataSet ds = new DataSet();
DataView dv = new DataView();
ds=BindDataToGrid();
if (ViewState["sortExpression"] != null)
{
dv = new DataView(ds.Tables[0]);
dv.Sort = (string)ViewState["sortExpression"] + " "
+ ViewState["SortOrder"];
}
else
dv = ds.Tables[0].DefaultView;
return dv;
}
private void AddSortImage(int columnIndex, GridViewRow headerRow)
{
Image sortImage = new Image();
if (GridViewSortDirection == SortDirection.Ascending)
{
sortImage.ImageUrl = "~/images/up.gif";
sortImage.AlternateText = "Ascending Order";
}
else {
sortImage.ImageUrl = "~/images/down.gif";
sortImage.AlternateText = "Descending Order";
}
headerRow.Cells[columnIndex].Controls.Add(sortImage);
} private int GetSortColumnIndex() {
foreach (DataControlField field in GridView1.Columns)
{
if (field.SortExpression ==
(string)ViewState["sortExpr"])
{
return GridView1.Columns.IndexOf(field);
}
}
return -1;
}
private SortDirection GridViewSortDirection
{ get
{
if (ViewState["SortDirection"] == null)
ViewState["SortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["SortDirection"];
}
set
{
ViewState["SortDirection"] = value;
}
}
Subscribe to:
Posts (Atom)