Making a row in gridview editable on double click

Posted by Adi under ASP.NET on 6/23/2012 | Points: 10 | Views : 3400 | Status : [Member] | Replies : 1
Hi guys....
i wanted to make my gridview rows editable on double click.........i referred to an article on this from .net funda itself. the link to the article is http://www.dotnetfunda.com/articles/article136.aspx......

however i have some problems.....

Whenevr i double click the row......
it remains as it is.........i.e. only the color of the row changes....since i hav given a color to row on doubleclick........The text boxes in the row appear when there is another page load i.e. when any other row is double clicked........thus when a row is dblclicked it becomes editble after another row is doubleclicked.......I want that the row shld become editable as soon as it is doubleclicked......Moreover i want that the first column of my gridview which actually shows the Primary key from the database remain as it is......the remaining cells of the row shld become editable........and i want to give a common update button at the bottom of my grid view. so that i can update using a single button only........Guys please help

here is my code.......

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton dblclkbtn = (LinkButton)e.Row.Cells[0].Controls[0];
string _jsdbl = ClientScript.GetPostBackClientHyperlink(dblclkbtn, "");
e.Row.Attributes["ondblclick"] += _jsdbl;
// e.Row.Attributes.Add("ondblclick", "Javascript:__doPostBack('DoubleClick','" + e.Row.RowIndex + "');");
string jsCommand = string.Format("__doPostBack('{0}','Edit${1}')",GridView1.ID, e.Row.RowIndex, GridView1.EditIndex);
foreach (TableCell c in e.Row.Cells)
{
if (c == e.Row.Cells[0])
{
}
else
{
c.Attributes["ondblclick"] = jsCommand;
}
}
}
//if (e.Row.RowType == DataControlRowType.DataRow)
//{
if (list != null)
{
if (list.Contains(e.Row.Cells[2].Text))
e.Row.BackColor = Color.Yellow;
else
e.Row.BackColor = Color.White;
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DoubleClick")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
GridViewEditEventArgs edit = new GridViewEditEventArgs(index);
edit.NewEditIndex = index;
object s=new object ();
if (GridView1.Rows.Count> 0)
{
GridView1.EditIndex= edit.NewEditIndex;
}
GridView1_RowEditing(s, edit);
// string msg = row.Cells[2].Text;
if (list != null)
{
if (list.Contains(row.Cells[2].Text))
{
list.Remove(row.Cells[2].Text);
row.BackColor = System.Drawing.Color.White;
}
else
{
list.Add(row.Cells[2].Text);
row.BackColor = System.Drawing.Color.Yellow;
}
}
else
{
list.Add(row.Cells[2].Text);
row.BackColor = System.Drawing.Color.Yellow;
}
}
Session["List"] = list;
}




Responses

Posted by: Gemamgall on: 6/27/2012 [Member] Starter | Points: 25

Up
0
Down
Please share the aspx side of code, so that i becomes more clear

Thanks and Regards,

Vinay Gandhi
www.quadtechindia.com

Adi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response