Friday, 20 April 2012
Add Data in Grid View by using footer Template
02:51
1 comment
1.Showfooter=true;
B. Go to Gridview's Smarttag and EditColume-
Select field srno then after click - Convert this field into a template field
C. Gridview's Smarttag -Edit Template
Grid View Tasks- select footer template
after selected any controle drag in thish tempalate
ending tempalate editing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
TextBox t1 = (TextBox)GridView1.FooterRow.FindControl("txtsrno");
TextBox t2 = (TextBox)GridView1.FooterRow.FindControl("txtname");
TextBox t3 = (TextBox)GridView1.FooterRow.FindControl("txtfather");
SqlDataSource1.InsertParameters["SrNo"].DefaultValue = t1.Text;
SqlDataSource1.InsertParameters["Name"].DefaultValue = t2.Text;
SqlDataSource1.InsertParameters["Father"].DefaultValue = t3.Text;
SqlDataSource1.Insert();
GridView1.DataBind();
}
}
Tuesday, 6 March 2012
Array with Structure and Array Resize Concept in C# .Net
Note: In this program we
will discuss about Array According to Array definition “Array is collection of similar type data means homogeneous elements but
here we will discuss How to insert
heterogeneous elements in Array for this we have concept Array with
Structure and another concept within
this program how to Resize Array in run time because when we insert less number
of elements from the size of array which we declare at the time of
array declaration then some memory will be wasted ………………..
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace cms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// declare structure for insert heterogeneous elements
struct customer
{
public int cusid;
public string fname;
public string lname;
public DateTime dob;
}
// declare array with one block because we resize array at run time
customer[] acus = new customer[1];
int index = 0;
//int count = 0;
//code for add new heterogeneous elements in array and resize array size…
private void btnadd_Click(object sender, EventArgs e)
{
acus[index].cusid = Convert.ToInt32(txtid.Text);
acus[index].fname = txtfname.Text;
acus[index].lname = txtlname.Text;
acus[index].dob = Convert.ToDateTime(txtdob.Text);
index++;
Array.Resize(ref acus, index + 1);
MessageBox.Show("data saved");
txtid.Text = "";
txtfname.Clear();
txtlname.Text = String.Empty;
txtdob.Text = "";
}
//code for search data with id
private void btnsearch_Click(object sender, EventArgs e)
{
bool chk = false;
for (int i = 0; i < index; i++)
{
if (txtid.Text == acus[i].cusid.ToString())
{
txtfname.Text = acus[i].fname;
txtlname.Text = acus[i].lname;
txtdob.Text = acus[i].dob.ToShortDateString();
chk = true;
break;
}
}
if (chk == false)
{
MessageBox.Show("not found");
}
}
//code for close From
private void btnclose_Click(object sender, EventArgs e)
{
this.Close();
}
//code for clear textboxs
private void btnclear_Click(object sender, EventArgs e)
{
txtid.Text = "";
txtfname.Text = "";
txtlname.Text = "";
txtdob.Text = "";
}
//code for delete element from array with id
private void btndelete_Click(object sender, EventArgs e)
{
for (int i = 0; i < index; i++)
{
if (txtid.Text == acus[i].cusid.ToString())
{
for (int j = i; j < index; j++)
{
acus[j] = acus[j + 1];
index--;
}
Array.Resize(ref acus, index + 1);
MessageBox.Show("Delete");
return;
}
}
}
//code get First element from Array
private void btnfirst_Click(object sender, EventArgs e)
{
txtid.Text = acus[0].cusid.ToString();e
txtfname.Text = acus[0].fname;
txtlname.Text = acus[0].lname;
txtdob.Text = acus[0].dob.ToShortDateString();
}
//code get last element from Array
private void btnlast_Click(object sender, EventArgs e)
{
txtid.Text = acus[index - 1].cusid.ToString();
txtfname.Text = acus[index - 1].fname;
txtlname.Text = acus[index - 1].lname;
txtdob.Text = acus[index - 1].dob.ToShortDateString();
}
//code get Next element from Array
private void btnnext_Click(object sender, EventArgs e)
{
int nxt = 0;
for (int i = 0; i < index; i++)
{
if (txtid.Text == acus[i].cusid.ToString())
{
nxt = i + 1;
}
}
if (nxt < index)
{
txtid.Text = acus[nxt].cusid.ToString();
txtfname.Text = acus[nxt].fname;
txtlname.Text = acus[nxt].lname;
txtdob.Text = acus[nxt].dob.ToShortDateString();
}
else
{
MessageBox.Show("data not found");
}
}
//code get Previouse elements from Array
private void btnprevious_Click(object sender, EventArgs e)
{
int pre = 0;
for (int i = 0; i > index; i--)
{
if (txtid.Text == acus[i].cusid.ToString())
{
pre = i - 1;
}
}
if (pre > 0)
{
txtid.Text = acus[pre].cusid.ToString();
txtfname.Text = acus[pre].fname;
txtlname.Text = acus[pre].lname;
txtdob.Text = acus[pre].dob.ToShortDateString();
}
else
{
MessageBox.Show("data not found");
}
}
//code for update element from Array with Id
private void btnupdate_Click(object sender, EventArgs e)
{
for (int i = 0; i < index; i++)
{
if (acus[i].cusid == Convert.ToInt32(txtid.Text)) ;
{
acus[index].cusid = Convert.ToInt32(txtid.Text);
acus[index].fname = txtfname.Text;
acus[index].lname = txtlname.Text;
acus[index].dob = Convert.ToDateTime(txtdob.Text);
} MessageBox.Show("updated");
}
}
}
}
Wednesday, 29 February 2012
Connectivity with Sql Server with ADO .Net
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace MyDataConnectivity
{
public partial class Form1 : Form
{
SqlConnection con;
SqlCommand cmd;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_insert_Click(object sender, EventArgs e)
{
// Connectivity in ADO .NET ........with Sql Parameter
try
{
con = new SqlConnection();
con.ConnectionString = "Data Source=KUSH-PC\\SQLSERVER2008; Initial Catalog=MyDemo; Integrated Security= SSPI";
con.Open();
cmd = new SqlCommand();
cmd.CommandText = "insert into customer_details (Customer_id,Customer_Fname,Customer_Lname,DOB,Father_Name,Mobile_No) Values('" + txtcustomerid.Text + "','" + txtcusfname.Text + "','" + txtcuslname.Text + "','" + txtcusdob.Text + "','" + txtfathername.Text + "','" + txtmobileno.Text + "')";
cmd.CommandText = "insert into customer_details (Customer_id,Customer_Fname,Customer_Lname,DOB,Father_Name,Mobile_No) Values('" + txtcustomerid.Text + "','" + txtcusfname.Text + "','" + txtcuslname.Text + "','" + txtcusdob.Text + "','" + txtfathername.Text + "','" + txtmobileno.Text + "')";
cmd.Connection = con;
cmd.ExecuteNonQuery();
MessageBox.Show("SAVED");
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
// Connectivity in ADO .NET ....................................with Sql Parameter
try
{
con = new SqlConnection("Data Source=KUSH-PC\\SQLSERVER2008; Initial Catalog=MyDemo; Integrated Security= SSPI");
con.Open();
cmd = new SqlCommand("insert into customer_detailsvalues(@Customer_id,@Customer_Fname,@Customer_Lname,@DOB,@Father_Name,@Mobile_No)", con);
cmd.Parameters.AddWithValue("@customer_id", txtcustomerid.Text);
cmd.Parameters.AddWithValue("@customer_fname", txtcusfname.Text);
cmd.Parameters.AddWithValue("@customer_lname", txtcuslname.Text);
cmd.Parameters.AddWithValue("@dob", Convert.ToDateTime(txtcusdob.Text));
cmd.Parameters.AddWithValue("@father_name", txtfathername.Text);
cmd.Parameters.AddWithValue("@mobile_no", txtmobileno.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("SAVED");
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//Connectivity in ADO .NET ....................................with DataSet Table Adapter (Disconnected Mode)
try
{
DataSet1TableAdapters.customer_detailsTableAdapter da = new DataSet1TableAdapters.customer_detailsTableAdapter();
da.Insert(txtcustomerid.Text, txtcusfname.Text, txtcuslname.Text, Convert.ToDateTime(txtcusdob.Text), txtfathername.Text, txtmobileno.Text);
MessageBox.Show("SAVED");
MessageBox.Show("SAVED");
}
catch (Exception ex)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
Subscribe to:
Posts (Atom)




.jpg)










