469,903 Members | 1,834 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,903 developers. It's quick & easy.

Images in datagrid!

Hi guys,
Could some one help me out? I have a datagrid where one Row is for
selecting from radiobuttonlist of too, one has to be chosen. When it's
chosen it is stored in the database and appears to the datagrid after
the insert button pressed. But now I have two images that are supposed
to correspond each of the radiobutton. I made them visible="false" but
I want when one selects one radiobutton the corresponding image
appears along: Visible="True". How could I go about this?
Thank you

Mar 9 '07 #1
4 1796

Presuming you are asking about client-side javascript dynamic change
of image in DataGrid (or GridView).

In ItemDataBound (or RowDataBound) event you need to find image (or
some it's container) by e.Item.FindControl (or e.Row.FindControl) and
then pass it's ClientID in javascript call of onclick attribute of
associated radio button (which may be found by similar e.Item/

The onlick attribute may be a javascript function accepting that id
and the sender (this). In that function depending on condition
this.value == true/false you may set
document.getElementById(checkBoxID).value = true/false

If client-side dynamicism is not needed or desired, you may trap
OnCheckChanged event alongwith AutoPostBack="true". But rather than
dedicated event handler in postback, still set visibility of image in
or after Item/RowDataBound (preferably in).

Mar 9 '07 #2
document.getElementById(checkBoxID).value = true/false

oops,,, document.getElementById(ImageOrContainerID).style. display =
"block" or "none"
Mar 9 '07 #3
Thanks Yaseen,
I'm getting a little bit lost. When you give me this code how I'm i
supposed to fix it into my code this is the code I'm using for the
The behind code:

protected void rblmood_SelectedIndexChanged(object
sender,System.EventArgs e)
RadioButtonList rbl = (RadioButtonList)sender;
Control parent = rbl.Parent;
while(!(parent is
parent = parent.Parent;
protected int SetState(object st)
string state = st.ToString();
return 0;

return 1;

Html code is:
<asp:TemplateColumn HeaderText="Mood Today">
<asp:Image id="imggm" runat="server" Visible="False" ImageUrl="file:///
<asp:Image id="imgbm" runat="server" Visible="False" ImageUrl="file:///
<asp:Label id=Label2 runat="server" text='<%#
DataBinder.Eval(Container,"DataItem.MoodToday")%>' >Label</asp:Label>
<asp:RadioButtonList id=rblmood runat="server" Width="104px"
AutoPostBack="True" SelectedIndex='<
%#SetState(DataBinder.Eval(Container.DataItem,"Moo dToday"))%>'
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>


Mar 9 '07 #4
I have just tried your advice but I get an error:
The type or namespace name 'document' could not be found (are you
missing a using directive or an assembly reference?)
What wrong?


Mar 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Reb | last post: by
13 posts views Thread by moondaddy | last post: by
9 posts views Thread by tshad | last post: by
9 posts views Thread by tshad | last post: by
2 posts views Thread by Tim::.. | last post: by
14 posts views Thread by Brett Sinclair | last post: by
7 posts views Thread by julian.tklim | last post: by
76 posts views Thread by rcoco | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.