How to send GridViewRowEventArgs to OnCheckedChanged

How to send GridViewRowEventArgs to OnCheckedChanged? It's not possible to just replace EventArgs with GridViewRowEventArgs.

    protected void Velg_CheckedChanged(object sender, EventArgs e)
    {
        Label2.Text = "asdasdasd";
    }
m-jansenAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
aki4uConnect With a Mentor Commented:
"I need to send a GridViewRowEventArgs to the OnCheckedChanged method. How to do it? It sounds difficult to me."
-you can't do this

To respond to a checkbox CheckedChanged event in DataGrid, you need to specify in html code of the CheckBox: OnCheckedChanged="Velg_CheckedChanged" and AutoPostBack="True".
Now, if you want to get some information about the cell where checkbox is copy this code:

protected void Velg_CheckedChanged(object sender, EventArgs e)
{
      CheckBox chk = (CheckBox)sender;
      TableCell cell= (TableCell)chk.NamingContainer.Controls[1];//assuming your checkbox is first column in DataGrid
      string cellText = cell.Text;
}
0
 
Hamed ZaghaghiProgrammerCommented:
It's not possible to replace these types
0
 
m-jansenAuthor Commented:
how to deal with it?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
aki4uCommented:
what are you trying to do?
0
 
m-jansenAuthor Commented:
>what are you trying to do?
when a checkbox is clicked another c# method should be run
0
 
m-jansenAuthor Commented:
I have actuallt almost figured out how to deal with it like this.

   protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            CheckBox Velg = (CheckBox)e.Row.FindControl("Velg");
            Velg.Attributes.Add("onclick", ""+ list.Add(32) +"");
        }
    }

but the value 32 does not add to my list when I click the select button
0
 
m-jansenAuthor Commented:
ops I mean the checkbox
0
 
aki4uCommented:
list.Add(32) is a codebehind(server side) what will not work with "onclick" event (client side).
0
 
m-jansenAuthor Commented:
If I can't use onclick and not use OnCheckedChanged. What to do then? There have to be a someway to handle this?
0
 
aki4uCommented:
you could use OnCheckedChanged, I don't see why not.                                      
0
 
m-jansenAuthor Commented:
Good. How would you suggest to it?
0
 
m-jansenAuthor Commented:
I need to send a GridViewRowEventArgs to the OnCheckedChanged method. How to do it? It sounds difficult to me.
0
 
orbulatCommented:
..
CheckBox Velg = (CheckBox)e.Row.FindControl("Velg");
Velg.CheckedChanged +=new EventHandler(Velg_CheckedChanged);

....

private void Velg_CheckedChanged(object sender, EventArgs e)
{
    ...
    //do your stuff
    ..
}
0
 
m-jansenAuthor Commented:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
CheckBox Velg = (CheckBox)e.Row.FindControl("Velg");
Velg.CheckedChanged += new EventHandler(Velg_CheckedChanged);
}

protected void Velg_CheckedChanged(object sender, EventArgs e) {
string s = e.Row.Cells[0].Text;
}


This code does not work.
0
 
m-jansenAuthor Commented:
Thanks for good help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.