C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to edit or delete in a gridview


Posted Date: 30 Apr 2008    Resource Type: Code Snippets    Category: C# Syntax

Posted By: mahua dutta       Member Level: Silver
Rating:     Points: 20



The following code sample shows how to edit or delete in a gridview
///////////////////////////
void bind()
{
ds = ob1.dbrdset("select * from student1");
GridView1.DataSource=ds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;
bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();

}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);

TextBox t1 = (TextBox)(GridView1.Rows[GridView1.EditIndex].Cells[0].Controls[0]);
TextBox t2 = (TextBox)(GridView1.Rows[GridView1.EditIndex].Cells[1].Controls[0]);
if (t1.Text == "")
{
//alert..


}
else if (t2.Text == "")
{
//alert..

}
else
{
cmd = ob1.dbcommand("updateproc");
//cmd.Parameters.Add("roll", SqlDbType.Int).Value = id;
cmd.Parameters.Add("roll", SqlDbType.Int).Value = Convert.ToInt32(t1.Text);
cmd.Parameters.Add("marks", SqlDbType.Int).Value = Convert.ToInt32(t2.Text);
cmd.Parameters.Add("dept", SqlDbType.VarChar, 50).Value = t3.Text;
cmd.Parameters.Add("name", SqlDbType.VarChar, 50).Value = t4.Text;
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
bind();
}

}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int i = (int)GridView1.DataKeys[e.RowIndex].Value;
cmd = ob1.dbcommand("deleteproc");
cmd.Parameters.Add("roll", SqlDbType.Int).Value = i;

GridView1.EditIndex = -1;
cmd.ExecuteNonQuery();
bind();
}




Responses

Author: Debasmit Samal    07 May 2008Member Level: Gold   Points : 2
When I am opening this page it is asking for Please enter your name. Please enter your roll number etc........

How u have done this for this perticular page


Author: Nithya    07 May 2008Member Level: Bronze   Points : 2
please send design view also


Author: Nithya    07 May 2008Member Level: Bronze   Points : 2
please send design view also


Author: shaik mohiuddin    10 May 2008Member Level: Gold   Points : 2
nice one but send design view also .


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Using Lock in C#
Previous Resource: How to delete from a datalist depending on checkbox selection
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use