473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1956

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

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
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,"Moo dToday"))%>'
Height="40px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
</EditItemTemplate>

Thanks.

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?

Thanks.

Mar 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Reb | last post by:
I am using a datagrid within another datagrid. My second datagrid is expand/collapse one. I am facing some error. This is my code. ExpandGrid.aspx <form id="Form1" method="post"...
13
by: moondaddy | last post by:
Happy Holidays All! I want to load a datagrid with images and text (Image, text, image, text, etc...). The data for this datagrid will be coming from sql server and the images are stored as files...
9
by: tshad | last post by:
Is there a way to use your own image in place of the automatic one that ASP uses when doing editing in your DataGrid pages? We already have a style of button we are using and would like to be...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
2
by: Tim::.. | last post by:
Hi I'm trying to create a little application that shows an image of a user when you mouseover there details in a datagrid. The datagrid is populated from an Active Directory Database and I...
14
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
76
by: rcoco | last post by:
Hi all, I'm facing this problem I have images on my website but when I Deploye the website on server the Images are not there I only get the X sign. How can I go about this. Thanks
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.