Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2008, 08:37 AM
Authorized User
 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

im sorry but i've tried this code and it gives me the following error

NullReferenceException

"Object reference not set to an instance of an object."

else i added a textbox control to the form and maked equal its text property to the gridview cell text property (fifth cell) but nothing was apperead in the textbox . i didnt understand why

 
Old February 28th, 2008, 09:19 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

As I stated in my previous post, if you are binding to a control the Text Property of your cell will return and empty string.

I just ran a variation of your code and it seemed to work fine:

foreach (GridViewRow gvr in gv.Rows)
{
            bool isChecked = ((CheckBox)gvr.FindControl("chkSec")).Checked;

            if (isChecked)
            {
                Label lbl = (Label)gvr.FindControl("lblID");
                str.Append(lbl.Text);
            }
}

What triggers your code to be run? Are you making sure to rebind your grid on postbacks?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 28th, 2008, 09:59 AM
Authorized User
 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks a lot ,it runs

 
Old February 28th, 2008, 10:24 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

For the sake of any other person that might be having the same issue, can you explain how you fixed your issue and what code you used to resolve your problem?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old February 28th, 2008, 12:56 PM
Authorized User
 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i've used this code :

protected void LinkButton1_Click(object sender, EventArgs e)
    {

        StringBuilder str = new StringBuilder();

        for (int i = 0; i < gv.Rows.Count; i++)
        {
            GridViewRow row = gv.Rows[i];
            bool isChecked = ((CheckBox)row.FindControl("chkSec")).Checked;

            if (isChecked)
            {
                str.AppendFormat("<p>{0}) {1}<br/></p>", ((Label)row.FindControl("lblID")).Text,((Label)row .FindControl("lblQID")).Text);
            }
        }
   Response.Write(str.ToString());
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
Confirmation with checkbox in gridview collie Visual Studio 2005 0 October 24th, 2007 06:13 AM
Checkbox in Gridview yukijocelyn ASP.NET 2.0 Basics 0 September 24th, 2007 12:32 AM
GridView Checkbox ItemTemplate angelicagm ASP.NET 2.0 Professional 3 May 31st, 2007 04:44 AM
Checkbox in GridView aliirfan84 ASP.NET 2.0 Professional 1 May 15th, 2007 03:59 PM
Gridview checkbox problems pauliehaha ASP.NET 2.0 Professional 1 May 3rd, 2007 04:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.