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;
using System.Data.SqlClient;
public partial class Home : System.Web.UI.Page
{
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(@"Data Source=....");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
int intCountryID = Convert.ToInt32(ddlCountry.SelectedValue.ToString());
string strCountry = txtlang.Text.Trim();
string strDesc = txtDescription.Text.Trim();
int intUserID = 1;
DateTime DTDate = DateTime.Now.Date;
if (txtlang.Text != string.Empty && txtDescription.Text != string.Empty)
{
cmd.Connection = con;
cmd.CommandText = "insert into tbl_language values(" + intCountryID + ",'" + strCountry + "','" + strDesc + "'," + intUserID + ",'" + DTDate + "'," + intUserID + ",'" + DTDate + "',1)";
cmd.ExecuteNonQuery();
BindData();
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Some fields are missing...')</script>");
}
}
protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
BindData();
}
public void GridView_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void GridView_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
BindData();
}
protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
BindData();
TaskGridView.EditIndex = -1;
BindData();
}
public void BindData()
{
con.Open();
cmd = new SqlCommand("select language_id,language_name,language_desc from tbl_language where ref_country_id = " + Convert.ToInt32(ddlCountry.SelectedValue.ToString()), con);
da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = true;
con.Close();
}
}
This is my code ..
What I need is there is two tables tbl_country,
tbl_language
(language_id
ref_country_id
language_name
language_desc
created_by
created_date
updated_by
updated_date
isactive )
..
if i click edit in grid it should be updated.
if i click delete it should be change it's field isactive to false state in tbl_language table.
*** All the codings i need in " .cs not in aspx "
Pls help me..
Thanks in advance..
Still i'm getting error..
protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int index = GridView1.EditIndex;
GridViewRow row = GridView1.Rows[index];
TextBox t1 = row.FindControl("TextBox2") as TextBox;
TextBox t2 = row.FindControl("TextBox3") as TextBox;
string t3 = GridView1.DataKeys[e.RowIndex].Value.ToString();
string cmdText = "Update tbl_language set language_name= '" + t1.Text + "' , language_desc= '" + t2.Text + "' where language_id='" + t3 + "'";
SqlCommand command = new SqlCommand(cmdText, con);
command.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
BindData();
}
public void BindData()
{
con.Open();
cmd = new SqlCommand("select language_id,language_name,language_desc from tbl_language where ref_country_id = " + Convert.ToInt32(ddlCountry.SelectedValue.ToString()), con);
da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
GridView1.Visible = true;
con.Close();
}
I'm getting error in rowupdating method...
line : string t3 = GridView1.DataKeys[e.RowIndex].Value.ToString();