TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
narasiman rao
NA
519
767.5k
i am doing using Gridview uisng asp.net csharp code
Aug 25 2012 1:30 AM
i am doing using Gridview uisng asp.net csharp code.in that i have following doubt.
this is my code as follows.
When i run error occurs as follows
,
type or namespace definition or end of file excepted.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Server=(local);initial catalog=Master;Trusted_Connection=True");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("SELECT CategoryID,CategoryName from quest", con);
DataTable dt = new DataTable();
da.Fill(dt);
DataRow dr = dt.NewRow();
dt.Rows.InsertAt(dr, 0);
GridView1.EditIndex = 0;
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text == "Insert")
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Insert into quest (CategoryName) values(CategoryName)";
cmd.Parameters.Add("CategoryName", SqlDbType.VarChar).Value = ((TextBox)GridView1.Rows[0].Cells[2].Controls[0]).Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
else
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Update quest SET CategoryName=@CategoryName where CategoryID=@CategoryID";
cmd.Parameters.Add("@CategoryName",SqlDbType.VarChar).Value=((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
cmd.Parameters.Add("@CategoryID",SqlDbType.Int).Value= Convert.ToInt32(GridView1.Rows[e.RowIndex].Cells[1].Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
Please help me.
Thanks,
Regards,
Rao.
Reply
Answers (
3
)
Compatibility issue between Microsoft Visual Studio 2005 and Microsoft Visual Web Developer 2010 Express
how to set grid image on top of the camera screen in metro style app