Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 October 22nd, 2009, 06:02 AM
Authorized User
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via ICQ to nkvd3941 Send a message via AIM to nkvd3941 Send a message via MSN to nkvd3941
Default Gridview

Hi Imar / All

I am about 1/2 way thru your Begiining ASP.NET 3.5 in C# & VB - find it to be excellent.

Got to gridview chapter - question is:
How do i build a gridview without using the wizards? ie to have more control on what i am doing, build the gridview from scratch, add in the columns, bind to the db.
Is their coding examples around of doing this, or even another wrox book for sale showing me just this? I would buy another book for this info alone.

For example, how to add a checkbox into the gridview that isnt bound to the underlying db, and how to interrogate the contents of the checkbox - i had major problems trying to find the value of the checkbox.

Many thanks

Last edited by nkvd3941; October 22nd, 2009 at 06:07 AM..
 
Old October 22nd, 2009, 06:21 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You may find what you need here:

http://www.highoncoding.com/Categori...r_Control.aspx

Alternatively, post some more details and we may be able to help you out here.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old October 22nd, 2009, 07:12 AM
Authorized User
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via ICQ to nkvd3941 Send a message via AIM to nkvd3941 Send a message via MSN to nkvd3941
Default

Hi

Thanks for quick reply.
What i am trying to do:

a. I have a gridview thats bound to a table, with 4 columns.
b. I have added a fifth column, a checkbox, using Edit fields
c. I wish to then iterate thru the gridview's rows, picking out the selected rows, and process those, using the key of the row to whatever processing.
I cant seem to find a value for the checkbox

Many thanks
 
Old October 22nd, 2009, 07:43 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You need to use FindControl on the GridViewRow to find the check box. Something like this should work:

Code:
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" 
    DataSourceID="SqlDataSource1">
  <Columns>
    <asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" 
           SortExpression="Id" />
  <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
    <asp:TemplateField>
      <ItemTemplate>
        <asp:CheckBox ID="CheckBox1" runat="server" />
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" />
This GridView is using a SqlDataSource with a simple select like SELECT Id, Description FROM SomeTable. The Id is an integer.

Then in the Click event handler of the button you can check the CheckBox like this:

Code:
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
  foreach (GridViewRow item in GridView1.Rows)
  {
    if (item.RowType == DataControlRowType.DataRow)
    {
      CheckBox myCheckBox = item.FindControl("CheckBox1") as CheckBox;
      if (myCheckBox != null && myCheckBox.Checked)
      {
        int primaryKey = Convert.ToInt32(GridView1.DataKeys[item.DataItemIndex].Value);
        Label1.Text += String.Format("{0}<br />", primaryKey);
      }
    }
  }
}
Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
nkvd3941 (October 22nd, 2009)
 
Old October 22nd, 2009, 09:05 AM
Authorized User
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via ICQ to nkvd3941 Send a message via AIM to nkvd3941 Send a message via MSN to nkvd3941
Default

Alleluia - many thanks
 
Old October 30th, 2009, 12:32 PM
Authorized User
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via ICQ to nkvd3941 Send a message via AIM to nkvd3941 Send a message via MSN to nkvd3941
Default

Hi again

Does "Edit and Continue" work in Web programming in the same way as in Windows programming? Every time I make a change to the c# code in web and try to continue, i get "The source file hase changed..." message and have to recompile everyhing before continuing.
 
Old October 30th, 2009, 12:51 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

It works in Web Application Projects, but AFAIK, it doesn't work in Web Site Projects....

For more info: http://whyiamright.wordpress.com/200...l-studio-2005/

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old October 31st, 2009, 10:33 AM
Authorized User
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via ICQ to nkvd3941 Send a message via AIM to nkvd3941 Send a message via MSN to nkvd3941
Default

a. This may sound a bit dim but i cant find the web project property pages anywhere. I have seen the same screen u pointed to on numerous web sites now. I have VS 2008 SP2
b. Whats the best place to set Session variables? I keep losing values of atext box, even though i am setting the Session variable in the TextChanged event. Any tips?
 
Old October 31st, 2009, 10:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
I have VS 2008 SP2
That's odd. Service Pack 1 is the latest official release.... ;-)

Quote:
i cant find the web project property pages anywhere
Try this:

1. Start VS 2008
2. Choose File | New Web Site (not File | New project)
3. Right-click the site in the Solution Explorer (not the actual solution if you see it, but the web site beneath it) and choose Property Pages.

However, like I said, and like the aticle seems to confirm, Edit and Continue is not supported in Web Site Projects (File | New Web Site) but only in Web Application Projects (File | New Project)

Quote:
Whats the best place to set Session variables?
It depends on what you want to accomplish. Session variables should not affect the text of a TextBox unless you set the text explicitly. Showing some code might shed some light on this.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old December 13th, 2009, 07:01 AM
Authorized User
 
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
Send a message via ICQ to nkvd3941 Send a message via AIM to nkvd3941 Send a message via MSN to nkvd3941
Default

Re: Chap 14, hooking into the RowDataBound event - i can successfully get values using the DataRowView; it it possible to *change* values in the cells. Also is it possible to change cell fonts / colors here?
Is this the right event to be doing this?

Last edited by nkvd3941; December 13th, 2009 at 07:04 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy One Row from Gridview to Gridview lvprasad2007 ASP.NET 2.0 Professional 0 July 28th, 2009 08:29 AM
GridView pady123 ASP.NET 2.0 Professional 0 November 13th, 2008 05:48 AM
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Gridview Thinlizzy ASP.NET 2.0 Basics 2 July 20th, 2007 08:33 AM
GridView Sheraz Khan ASP.NET 2.0 Basics 1 July 19th, 2007 10:28 AM





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