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

October 22nd, 2009, 06:02 AM
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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..
|

October 22nd, 2009, 06:21 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

October 22nd, 2009, 07:12 AM
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|

October 22nd, 2009, 07:43 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
The Following User Says Thank You to Imar For This Useful Post:
|
|

October 22nd, 2009, 09:05 AM
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Alleluia - many thanks
|

October 30th, 2009, 12:32 PM
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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.
|

October 30th, 2009, 12:51 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

October 31st, 2009, 10:33 AM
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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?
|

October 31st, 2009, 10:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

December 13th, 2009, 07:01 AM
|
Authorized User
|
|
Join Date: Oct 2009
Posts: 19
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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..
|
|
 |