Monday, May 30, 2011
Sunday, May 29, 2011
How to create dynamic GRID VIEW in asp.net
public void loaddynamicgrid()
{
DataTable dt = new DataTable();
DataColumn dc;
DataRow dRow;
dc = new DataColumn("Date", typeof(DateTime));
dt.Columns.Add(dc);
dc = new DataColumn("Name", typeof(Int64));
dt.Columns.Add(dc);
SqlDataAdapter da = new SqlDataAdapter("select * from Tbl_Emp", Sqlconnectionstring);
DataSet ds = new DataSet();
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
dRow = dt.NewRow();
dt.Rows.Add(dRow);
dt.Rows[i][0] = ds.Tables[0].Rows[i]["date"].ToString();
dt.Rows[i][1] = ds.Tables[0].Rows[i]["name"].ToString();
}
}
How to add dynamic footer in dynamic Grid View with ASP.NET
This code use after Binding a gridview.
GridViewRow footerRow = GridView1.FooterRow;
Label lbl = new Label();
lbl.Text = "Create Footer Row";
footerRow.Cells[2].Controls.Add(lbl);
Tuesday, May 24, 2011
How to set identity seed in SQL SERVER by QUERY
If u want next number is 5000
then set seed as:
DBCC CHECKIDENT (tablename, reseed, 4999)
then set seed as:
DBCC CHECKIDENT (tablename, reseed, 4999)
Thursday, April 21, 2011
How to reset web form "CONTROL in ASP.NET" after save data
//call this function after completion of insert query
ClearInputs(Page.Controls);
private void ClearInputs(ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
{
((TextBox)ctrl).Text = string.Empty;
}
else if (ctrl is DropDownList)
{
((DropDownList)ctrl).ClearSelection();
}
ClearInputs(ctrl.Controls);
}
}
ClearInputs(Page.Controls);
private void ClearInputs(ControlCollection ctrls)
{
foreach (Control ctrl in ctrls)
{
if (ctrl is TextBox)
{
((TextBox)ctrl).Text = string.Empty;
}
else if (ctrl is DropDownList)
{
((DropDownList)ctrl).ClearSelection();
}
ClearInputs(ctrl.Controls);
}
}
Tuesday, April 5, 2011
select gridview(template column) row index on button click
GridViewRow row = ((Button)sender).Parent.Parent as GridViewRow;
int index = row.RowIndex;
int index = row.RowIndex;
Thursday, March 31, 2011
Import data from sqlserver into Excel Sheet Using DataTable
static DataTable dta;
SqlDataAdapter da = new SqlDataAdapter("select * from Emp", conn);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
dta = ds.Tables[0];
}
string attachment = "attachment; filename=Address.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dta.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dta.Rows)
{
tab = "";
for (i = 0; i < dta.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
Subscribe to:
Comments (Atom)





