Grid view.aspx:-
Camera Identity | AutoPostBack="True"> | |
Camera URL | ||
FTP Folder | ||
Email ID | ||
Password | ||
Contact Number | ||
OnClick="imgsubmt_Click" /> | ||
CellPadding="3" Height="150px" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" HorizontalAlign="Center" AutoGenerateSelectButton="True" onselectedindexchanged="gvconfig_SelectIndexChanged" AutoGenerateDeleteButton="True" onrowdeleting="gvconfig_RowDeleting"> | ||
Grid view.CS:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using MySql.Data.MySqlClient;
public partial class Gridview : System.Web.UI.Page
{
string cloudeyes;
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
cloudeyes = ConfigurationManager.ConnectionStrings["cloudeyes"].ToString();
if (!IsPostBack)
{
Bind();
gvconfig.Visible = true;
}
}
private void Bind()
{
MySqlConnection con = new MySqlConnection(cloudeyes);
con.Open();
MySqlCommand cmd = new MySqlCommand("sp_select", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
con.Close();
dt.Clear();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
gvconfig.DataSource = dt;
gvconfig.DataBind();
}
}
public void clearcontrolles()
{
txtCI.Text = "";
txtCU.Text = "";
txtFTP.Text = "";
txtmail.Text = "";
txtpwd.Text = "";
txtcontct.Text = "";
gvconfig.Visible = true;
}
protected void gvconfig_SelectIndexChanged(object sender, EventArgs e)
{
txtCI.Text=gvconfig.SelectedRow.Cells[1].Text;
txtCU.Text=gvconfig.SelectedRow.Cells[2].Text;
txtFTP.Text=gvconfig.SelectedRow.Cells[3].Text;
txtmail.Text=gvconfig.SelectedRow.Cells[4].Text;
txtpwd.Text=gvconfig.SelectedRow.Cells[5].Text;
txtcontct.Text=gvconfig.SelectedRow.Cells[6].Text;
}
protected void imgsubmt_Click(object sender, ImageClickEventArgs e)
{
MySqlConnection con = new MySqlConnection(cloudeyes);
con.Open();
MySqlCommand cmd = new MySqlCommand("sp_webcloud_config", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("scamid", MySqlDbType.VarChar).Value = txtCI.Text;
cmd.Parameters.Add("scamurl", MySqlDbType.VarChar).Value = txtCU.Text;
cmd.Parameters.Add("sftpfold", MySqlDbType.VarChar).Value = txtFTP.Text;
cmd.Parameters.Add("semailid", MySqlDbType.VarChar).Value = txtmail.Text;
cmd.Parameters.Add("spwd", MySqlDbType.VarChar).Value = txtpwd.Text;
cmd.Parameters.Add("scontct", MySqlDbType.VarChar).Value = txtcontct.Text;
cmd.ExecuteNonQuery();
Bind();
clearcontrolles();
gvconfig.Visible = true;
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
clearcontrolles();
}
protected void txtCI_TextChanged(object sender, EventArgs e)
{
string Name = txtCI.Text;
string url = Name + ".tenvis.info";
txtCU.Text = url;
string ftp = "/cctv/" + Name;
txtFTP.Text = ftp;
}
protected void gvconfig_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
// string Camers_ID = ((txtCI.Text)(gvconfig.Rows[e.RowIndex].Cells[0].Text);
//gvconfig.EditIndex = -1;
}
}
Satyapriya NayakPosted Apr 29, 2013, 9:26 AM
using System;
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;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//SqlConnection conn = new SqlConnection(connStr);
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataTable dataTable;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
Session["sortBy"] = null;
if (!IsPostBack)
{
FillVendorGrid();
}
}
private void FillVendorGrid()
{
SqlConnection conn = new SqlConnection(connStr);
dataTable = new DataTable();
cmd.Connection = conn;
cmd.CommandText = "SELECT * FROM Vendor";
ad = new SqlDataAdapter(cmd);
ad.Fill(dataTable);
ResultGridView.DataSource = dataTable;
ResultGridView.DataBind();
}
protected void ResultGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
ResultGridView.EditIndex = e.NewEditIndex;
FillVendorGrid();
}
protected void ResultGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
ResultGridView.PageIndex = e.NewPageIndex;
FillVendorGrid();
}
protected void ResultGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
cmd.Connection = conn;
cmd.CommandText = "DELETE FROM Vendor WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
FillVendorGrid();
}
protected void ResultGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtFName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtFName");
TextBox txtLName = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtLName");
TextBox txtCity = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCity");
TextBox txtState = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtState");
TextBox txtCountry = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtCountry");
TextBox txtDescription = (TextBox)ResultGridView.Rows[e.RowIndex].FindControl("txtDescription");
SqlConnection conn = new SqlConnection(connStr);
cmd.Connection = conn;
cmd.CommandText = "UPDATE Vendor SET VendorFName ='" + txtFName.Text + "',VendorLName ='" + txtLName.Text + "',VendorCity ='" + txtCity.Text + "',VendorState ='" + txtState.Text + "',VendorCountry ='" + txtCountry.Text + "',VendorDescription ='" + txtDescription.Text + "' WHERE VendorId='" + ResultGridView.DataKeys[e.RowIndex].Values[0].ToString() + "'";
conn.Open();
cmd.ExecuteNonQuery();
ResultGridView.EditIndex = -1;
FillVendorGrid();
conn.Close();
}
protected void ResultGridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
ResultGridView.EditIndex = -1;
FillVendorGrid();
}
protected void ResultGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox txtFName = (TextBox)ResultGridView.FooterRow.FindControl("txtFName1");
TextBox txtLName = (TextBox)ResultGridView.FooterRow.FindControl("txtLName1");
TextBox txtCity = (TextBox)ResultGridView.FooterRow.FindControl("txtCity1");
TextBox txtState = (TextBox)ResultGridView.FooterRow.FindControl("txtState1");
TextBox txtCountry = (TextBox)ResultGridView.FooterRow.FindControl("txtCountry1");
TextBox txtDescription = (TextBox)ResultGridView.FooterRow.FindControl("txtDescription1");
SqlConnection conn = new SqlConnection(connStr);
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Vendor(VendorFName, VendorLName,VendorCity,VendorState,VendorCountry,VendorDescription) Values('" + txtFName.Text + "', '" + txtLName.Text + "', '" + txtCity.Text + "', '" + txtState.Text + "', '" + txtCountry.Text + "' , '" + txtDescription.Text + "')";
conn.Open();
cmd.ExecuteNonQuery();
FillVendorGrid();
conn.Close();
}
}
protected void btn_search_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
str = "select * from Vendor where VendorFName like '" + TextBox1.Text + "%'";
cmd = new SqlCommand(str, conn);
sqlda = new SqlDataAdapter(cmd);
ds = new DataSet();
sqlda.Fill(ds, "Vendor");
conn.Close();
ResultGridView.DataSource = ds;
ResultGridView.DataMember = "Vendor";
ResultGridView.DataBind();
}
protected void ResultGridView_Sorting(object sender, GridViewSortEventArgs e)
{
Session["sortBy"] = e.SortExpression;
FillVendorGrid();
}
}