Images in datagrid!

R

rcoco

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
 
M

Muhammad Naveed Yaseen

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/
Row.FindControl).

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).
 
M

Muhammad Naveed Yaseen

document.getElementById(checkBoxID).value = true/false

oops,,, document.getElementById(ImageOrContainerID).style.display =
"block" or "none"
 
R

rcoco

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
radiobutton.
The behind code:

protected void rblmood_SelectedIndexChanged(object
sender,System.EventArgs e)
{
RadioButtonList rbl = (RadioButtonList)sender;
Control parent = rbl.Parent;
while(!(parent is
System.Web.UI.WebControls.DataGridItem))
{
parent = parent.Parent;
}
}
protected int SetState(object st)
{
string state = st.ToString();
if(state.Equals("True"))
{
return 0;

}
else
{
return 1;
}
}

Html code is:
<asp:TemplateColumn HeaderText="Mood Today">
<ItemTemplate>
<asp:Image id="imggm" runat="server" Visible="False" ImageUrl="file:///
C:\Inetpub\wwwroot\DashBoard\Moods\laughing.gif"></asp:Image>
<asp:Image id="imgbm" runat="server" Visible="False" ImageUrl="file:///
C:\Inetpub\wwwroot\DashBoard\Moods\sad.gif"></asp:Image>
<asp:Label id=Label2 runat="server" text='<%#
DataBinder.Eval(Container,"DataItem.MoodToday")%>'>Label</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButtonList id=rblmood runat="server" Width="104px"
AutoPostBack="True" SelectedIndex='<
%#SetState(DataBinder.Eval(Container.DataItem,"MoodToday"))%>'
Height="40px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
</EditItemTemplate>

Thanks.
 
R

rcoco

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?

Thanks.
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top