AspdotnetCodes.com
Search
Articles
Books
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
 need immediately
Posted by jern c j on  6/20/2009 2:44:38 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
please send me the codes for
grid view row selection,editing,updating,cancel?
and
grid view check box list?

Post Your Reply Post New Question

 Viewer's Reply
Try to do this it may help you
Answered By RAJESH KUMAR VISHWAKARMA on 9/19/2009 12:47:57 AM
protected void EditClick(object sender, EventArgs e)
{
LinkButton button = (LinkButton)sender;
GridView grid = (GridView)this.FindParent(button, typeof(GridView));

int index = GetItemIndex(button.UniqueID);
grid.EditIndex = index;
grid.DataBind();
}

protected void UpdateClick(object sender, EventArgs e)
{
LinkButton button = (LinkButton)sender;
}

protected void CancelClick(object sender, EventArgs e)
{
LinkButton button = (LinkButton)sender;
}

private int GetItemIndex(string input)
{
string pattern = @"ctl(?<index>\d+)";
Match match = Regex.Match(input, pattern);

if (match.Success)
return int.Parse(match.Groups["index"].Value) - 2;
return -1;
}

private Control FindParent(Control ctrl, Type type)
{
while (ctrl.GetType() != type)
ctrl = ctrl.Parent;

return ctrl;
}

protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{

}
protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView grid = (GridView)sender;
grid.EditIndex = -1;
grid.DataBind();
}
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
// Execute update SQL.
}
=============================

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;
using System.IO;



public partial class _Default : System.Web.UI.Page
{
CustomersCls customer = new CustomersCls();
protected void Page_Load(object sender, EventArgs e)
{

If(!IsPostBack);
{
FillCustomerInGrid();
}

}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList cmbType = (DropDownList)e.Row.FindControl("cmbType");

if (cmbType != null)
{
cmbType.DataSource = customer.FetchCustomerType();
cmbType.DataBind();
cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();
}
}

if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList cmbNewType = (DropDownList)e.Row.FindControl("cmbNewType");
cmbNewType.DataSource = customer.FetchCustomerType();
cmbNewType.DataBind();
}
//cmbType.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();

}

private void FillCustomerInGrid()
{
DataTable dtCustomer = customer.Fetch();

if (dtCustomer.Rows.Count > 0)
{
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
}
else
{
dtCustomer.Rows.Add(dtCustomer.NewRow());
GridView1.DataSource = dtCustomer;
GridView1.DataBind();

int TotalColumns = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = TotalColumns;
GridView1.Rows[0].Cells[0].Text = "No Record Found";
}




}


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddNew"))
{
TextBox txtNewName = (TextBox)GridView1.FooterRow.FindControl("txtNewName");
DropDownList cmbNewGender = (DropDownList)GridView1.FooterRow.FindControl("cmbNewGender");
TextBox txtNewCity = (TextBox)GridView1.FooterRow.FindControl("txtNewCity");
TextBox txtNewState = (TextBox)GridView1.FooterRow.FindControl("txtNewState");
DropDownList cmbNewType = (DropDownList)GridView1.FooterRow.FindControl("cmbNewType");

customer.Insert(txtNewName.Text, cmbNewGender.SelectedValue, txtNewCity.Text, txtNewState.Text, cmbNewType.SelectedValue);
FillCustomerInGrid();
}
}



protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
FillCustomerInGrid();
}


protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
FillCustomerInGrid();
}




protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox txtName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtN
 
Post Your Reply If you still have problem, post it again under this reply for better response.

 
Sponsored by
Windows 8: 50 Questions and Answers You Need to Make a Decision (Normally $9.95)
Simply JavaScript - Free 150 Page Preview!
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter