GridView and hidden field

G

Guest

i have a GridView and a hidden field :
<asp:TemplateField Visible=false >
<ItemTemplate >
<asp:HiddenField Value="<%#Eval("isActive")%>"
id="hidIsActive" runat=server />
</ItemTemplate>
</asp:TemplateField>
1)when i check the sorce of html i dont see the hidden field - why is that?
2)on RowDataBound event, when i check the rows i want to check thr above
field value,and to do something on certin conditions.
the thing is that its value is set in a "Value" property while i try to
access using :
e.Row.Cells(5).Text
i wont get anything beacuse i access the wrong properrty
what can i do?
thnaks in advance
Peleg
 
Joined
Jul 11, 2007
Messages
4
Reaction score
0
Hello!

Depending on your need, it may be best to use a DataKey instead of the hidden field.

Set the name in your gridview with:

DataKeyNames="KeyName"

Use in your code like:

int ValueName = (int)MyGridView.DataKeys[RowIndex].Value;

Hope this helps,

thanks.
 
M

Masudur

i have a GridView and a hidden field :
<asp:TemplateField Visible=false >
<ItemTemplate >
<asp:HiddenField Value="<%#Eval("isActive")%>"
id="hidIsActive" runat=server />
</ItemTemplate>
</asp:TemplateField>
1)when i check the sorce of html i dont see the hidden field - why is that?
2)on RowDataBound event, when i check the rows i want to check thr above
field value,and to do something on certin conditions.
the thing is that its value is set in a "Value" property while i try to
access using :
e.Row.Cells(5).Text
i wont get anything beacuse i access the wrong properrty
what can i do?
thnaks in advance
Peleg

Hi...

"1)when i check the sorce of html i dont see the hidden field - why is
that?"
hi id you set any controls property to visible=false... asp.net does
not render them in client page....
i am not sure wheither hidden value also do that or not...
you can use html hidden input field to test that... (ofcourse with
runat server attribute)

i can see that you are using hidden field... but is that necessary?
what is "isActive"? doesn't seems to me it is coming from any
dataitem.. ratherthan page property...
if you want to perform any job depending on a cell value of the
dataitem... you should do in rowdatabound.. as i can see that you are
already doing that... so next thing is after accomplish your job...
you what to do some business on, lets say rowcommand... or
itemcommand,, in that case i assume you want to save the value
"IsActive" with the row...

well you can use e.row.attribute.add.... to add some attribute value
in itemdataboud...
and then retrive in row command....

Thanks
Md. Masudur Rahman (Munna)
kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
G

Guest

i think that the e.row.attribute.add is the solution
how in the RowDataBound event i can get the value on each row so
i can use it for diffrent things
thnaks
peleg
 
M

Masudur

i think that the e.row.attribute.add is the solution
how in the RowDataBound event i can get the value on each row so
i can use it for diffrent things
thnaks
peleg

Hi...


protected void GridViewTasks_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("myCustomAttribute", true);
}
}

this is the code for adding attribute to a row in rowdatabound
i think i am kind of missing the point... what exactly you are trying
to accomplish?


Thanks
Md. Masudur Rahman (Munna)
kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
G

Guest

ow now that i think i am not sure this is a good solutuin
beacuse i wanted from start to put a hidden value beacuwe i got it from the db
and the when the RowDataBound evernt occurs
by the hidden value i put in each row i want to change the row color
so what the correct way to do it?
thnaks
peleg
 
M

Masudur

ow now that i think i am not sure this is a good solutuin
beacuse i wanted from start to put a hidden value beacuwe i got it from the db
and the when the RowDataBound evernt occurs
by the hidden value i put in each row i want to change the row color
so what the correct way to do it?
thnaks
peleg

Well...

hi... i got it...
since you what it from beginning ... it kind of difficult........
because after itemdatabound things will be there.... but still you
have the option...
since you are binding the grid view against some data source...the
item you want to embade is already in your dataitem... right?
so why don't you just use e.Row.DataItem and cust it to appropriate
type... and then check value....

Thanks
Md. Masudur Rahman (Munna)
kaz Software Ltd.
www.kaz.com.bd
http://munnacs.110mb.com
 
G

Guest

u actullay mean that the DataItem in e.Row.DataItem
will still contain all the values that i have in my select
but are not actually visible to the user?
if yes then GREAT!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top