What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 10828 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET > Making a row in gridview editable on double click ...
Adi

Making a row in gridview editable on double click

Replies: 1 | Posted by: Adi on 6/23/2012 | Category: ASP.NET Forums | Views: 1174 | Status: [Member] | Points: 10  


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;
}


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Gemamgall
Gemamgall  
Posted on: 6/27/2012 2:37:29 PM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 9:31:40 PM