 |
| ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.1 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
|
|
|
|

January 10th, 2004, 01:22 AM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
unreachable column
hi all,
i have a datagrid which the first column is the id.
i use code behind to get the column value but it seems that when i use the visible="false" i cant seem to get it (i dont want to show this column.
below are the relavent code parts:
form:
<asp:TemplateColumn HeaderText="in_id" visible="false">
<FooterTemplate>
<asp:TextBox ID="in_id" Columns="7" Runat="Server" />
</FooterTemplate>
<ItemTemplate >
<%# DataBinder.Eval(Container.DataItem, "in_id") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="in_id" Columns="7"
Text='<%# DataBinder.Eval(Container.DataItem, "in_id") %>' Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
code behind:
string in_id = ((TextBox)e.Item.FindControl("in_id")).Text;
how should i do it ?
thanks in advance
Yuval
Yuval Kronenfeld
Web Developer
__________________
Yuval Kronenfeld
Israel
|
|

January 10th, 2004, 11:10 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Where are you making that call in the code-behind?
You have an item template where you are just writing out the value. For an "Item" (vs. "EditItem") you won't be able to find any controls in the datagrid item. The value will just be in there as text.
If you are working with a hidden column, why do you have template's set up? It would seem to me to be much easier to just use a hidden bound column. Then when that column appears in any type of datagrid item it will always show up as just text so you can access it with e.Item.Cells(n).Text
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 11th, 2004, 04:31 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
if i use boundColumn with visible=false,is it reasonable that i cant get the e.Item.Cells(0).Text value of the first (hidden) column ?when i use visible=true i have no problems....
Yuval Kronenfeld
Web Developer
|
|

January 12th, 2004, 11:01 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
How is it reasonable that you can't get the column's value? Have you tried it? I do this all the time. I put in a hidden bound column on fields that have data but not the right representation I need in the grid or a column that has data I want to have available but don't want to show (like a row ID). The one thing to keep in mind is that you have to take into account the hidden columns when using the column indexes.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 12th, 2004, 01:37 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
allow me to better explain myself:
i have a datagrid with update+insert capabilities(for inserting new row i use the footer).
I have a template column for each of the colmun to define their visual appearnce when they are in edit mode.
my first column is the raw id and that column should be hidden.
if i dont define a templateColumn for the ID column but instead use a boundColumn i get nothing in return to the following :
string in_id = e.Item.Cells[0].Text;
which is defined in the event handler for "update"
if i use:
string in_id =((TextBox)e.Item.FindControl("in_id")).Text;
it throws me an Exception :
System.NullReferenceException: Object reference not set to an instance of an object
can you tell what am i doing wrong?
Yuval Kronenfeld
Web Developer
|
|

January 12th, 2004, 04:00 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Aha... Ok. I apologize for my quick responses. I forgot a vital bit of information.
When you use a standard bound column, .net creates the default textbox for editing. This is happening for your ID column, but of course, you can't see it. The name of the textbox will be whatever .net generates for the name as you've most likely seen in the output HTML.
The key is to make the hidden bound column also readonly. Then the grid will not draw a text box for you and you can always access the value with Cells(0).Text no matter what mode that ItemType that DataGridItem is.
<asp:BoundColumn DataField="Item_ID" Visible="False" ReadOnly="True" />
Sorry for the confusion.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

January 12th, 2004, 04:43 PM
|
|
Authorized User
|
|
Join Date: Nov 2003
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ladies and Gentelmans - We got Him !
Thank you very much,it works just fine now....
Yuval Kronenfeld
Web Developer
|
|

February 26th, 2004, 06:26 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How did you get it working. I'm having the same problems. I tried what the others have stated and it seems to not work.
Quote:
quote:Originally posted by yuvalk
Ladies and Gentelmans - We got Him !
Thank you very much,it works just fine now....
Yuval Kronenfeld
Web Developer
|
|
|

February 26th, 2004, 06:29 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have tried what you have suggested and I get this error.
Specified argument was out of the range of valid values. Parameter name: index
When I make the column visible...It works fine. thanks for your time.
Quote:
quote:Originally posted by planoie
Aha... Ok. I apologize for my quick responses. I forgot a vital bit of information.
When you use a standard bound column, .net creates the default textbox for editing. This is happening for your ID column, but of course, you can't see it. The name of the textbox will be whatever .net generates for the name as you've most likely seen in the output HTML.
The key is to make the hidden bound column also readonly. Then the grid will not draw a text box for you and you can always access the value with Cells(0).Text no matter what mode that ItemType that DataGridItem is.
<asp:BoundColumn DataField="Item_ID" Visible="False" ReadOnly="True" />
Sorry for the confusion.
Peter
------------------------------------------------------
Work smarter, not harder.
|
|
|

February 27th, 2004, 11:41 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I have recently learned a better way to do this. Specify the field that contains your table's row identifier in the DataKeyField attribute of the datagrid. This keeps an internal collection of the key associated with each row in the grid. Then when you need to use the key in one of the datagrid event handlers, you reference it like this:
grdMyDataGrid.DataKeys(e.Item.ItemIndex)
Peter
------------------------------------------------------
Work smarter, not harder.
|
|
 |