Solved

How to send GridViewRowEventArgs to OnCheckedChanged

Posted on 2006-06-29
15
771 Views
Last Modified: 2010-05-18
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";
    }
0
Comment
Question by:m-jansen
15 Comments
 
LVL 9

Expert Comment

by:zaghaghi
Comment Utility
It's not possible to replace these types
0
 

Author Comment

by:m-jansen
Comment Utility
how to deal with it?
0
 
LVL 10

Expert Comment

by:aki4u
Comment Utility
what are you trying to do?
0
 

Author Comment

by:m-jansen
Comment Utility
>what are you trying to do?
when a checkbox is clicked another c# method should be run
0
 

Author Comment

by:m-jansen
Comment Utility
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
 

Author Comment

by:m-jansen
Comment Utility
ops I mean the checkbox
0
 
LVL 10

Expert Comment

by:aki4u
Comment Utility
list.Add(32) is a codebehind(server side) what will not work with "onclick" event (client side).
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:m-jansen
Comment Utility
If I can't use onclick and not use OnCheckedChanged. What to do then? There have to be a someway to handle this?
0
 
LVL 10

Expert Comment

by:aki4u
Comment Utility
you could use OnCheckedChanged, I don't see why not.                                      
0
 

Author Comment

by:m-jansen
Comment Utility
Good. How would you suggest to it?
0
 

Author Comment

by:m-jansen
Comment Utility
I need to send a GridViewRowEventArgs to the OnCheckedChanged method. How to do it? It sounds difficult to me.
0
 
LVL 10

Expert Comment

by:orbulat
Comment Utility
..
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
 

Author Comment

by:m-jansen
Comment Utility
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
 
LVL 10

Accepted Solution

by:
aki4u earned 100 total points
Comment Utility
"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
 

Author Comment

by:m-jansen
Comment Utility
Thanks for good help
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now