Images on server.

R

rcoco

Hi,
have just tryed this but it seems not to work? where is it wrong?
if(st5.SelectedValue=="Bad Mood")
{
st5.SelectedValue="Images/sad.gif";}
else if(st5.SelectedValue=="Good Mood")
{
st5.SelectedValue="Images/laughing.gif";}
And this is the error I'm getting:
Specified argument was out of the range of valid values. Parameter
name: Images/laughing.gif.
Thanks
st5 is your RadioButtonList
st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[1].FindControl(­­­­"rblmood");
so, what do you want to get using
st5.SelectedValue="Images/laughing.gif";
?
Sorry I've been away for some time. Yes st5 is my RadioButtonList. I
want the image laughing to come along when good mood is selected.
that's: st5.SelectedValue="Images/laughing.gif";
Thanks.- Hide quoted text -
- Show quoted text -

1) SelectedValue is a read-only property and you cannot assign a value
using st5.SelectedValue=...

2) st5 is a RadioButtonList and it cannot be equal to the "Images/
laughing.gif"- Hide quoted text -

- Show quoted text -

Is that the reason I'm getting this error:
Specified argument was out of the range of valid values. Parameter
name: Images/laughing.gif ?
Thanks
 
G

Guest

Hi,
have just tryed this but it seems not to work? where is it wrong?
if(st5.SelectedValue=="Bad Mood")
{
st5.SelectedValue="Images/sad.gif";}
else if(st5.SelectedValue=="Good Mood")
{
st5.SelectedValue="Images/laughing.gif";}
And this is the error I'm getting:
Specified argument was out of the range of valid values. Parameter
name: Images/laughing.gif.
Thanks
st5 is your RadioButtonList
st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[1].FindControl(­­­­­"rblmood");
so, what do you want to get using
st5.SelectedValue="Images/laughing.gif";
?
Sorry I've been away for some time. Yes st5 is my RadioButtonList. I
want the image laughing to come along when good mood is selected.
that's: st5.SelectedValue="Images/laughing.gif";
Thanks.- Hide quoted text -
- Show quoted text -
1) SelectedValue is a read-only property and you cannot assign a value
using st5.SelectedValue=...
2) st5 is a RadioButtonList and it cannot be equal to the "Images/
laughing.gif"- Hide quoted text -
- Show quoted text -

Is that the reason I'm getting this error:
Specified argument was out of the range of valid values. Parameter
name: Images/laughing.gif ?
Thanks- Hide quoted text -

- Show quoted text -

Wait, I think I made a mistake telling that it's a read-only:

MSDN: "Gets the value of the selected item in the list control, or
selects the item in the list control that contains the specified
value."
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

Sorry.

The error message "Specified argument was out of the range of valid
values. Parameter name: Images/laughing.gif" means that there is no
such value "Images/laughing.gif".
 
G

Guest

How can I make it work? Please help me.
thanks

Mark, no problem, actually I don't know why I thought it's a read-only
property. Maybe I had never used that before.

Rcoco,

You should understand conceptually what you are doing, rather than
following copy-and-paste code blindly. Your program is working as you
designed it, and not as you might think it should work.

You have to understand what the "out of the range of valid values"
means. This means that st5 (a RadioButtonList) has no value named
"Images/laughing.gif". I cannot answer, how you can make it working,
because I don't know how it should work. You used the following code
before:

imgDaily.ImageUrl = "imgbm"

Now, you are using

st5.SelectedValue = "..."

Why did you change this and what is the logic behind?

I thought, you wanted to change an image. Using st5.SelectedValue you
will change selection (a point) of the radio button.

If you definitely need to change the selected item in the
RadioButtonList you should know what values it has. Look in your code
where you bind the values (dataset, whatever) to this control.
 
G

Guest

Rcoco,

You should understand conceptually what you are doing, rather than
following copy-and-paste code blindly. Your program is working as you
designed it, and not as you might think it should work.

You have to understand what the "out of the range of valid values"
means. This means that st5 (a RadioButtonList) has no value named
"Images/laughing.gif". I cannot answer, how you can make it working,
because I don't know how it should work. You used the following code
before:

imgDaily.ImageUrl = "imgbm"

Now, you are using

st5.SelectedValue = "..."

Why did you change this and what is the logic behind?

I thought, you wanted to change an image. Using st5.SelectedValue you
will change selection (a point) of the radio button.

If you definitely need to change the selected item in the
RadioButtonList you should know what values it has. Look in your code
where you bind the values (dataset, whatever) to this control.- Hide quoted text -

- Show quoted text -

P.S.

If you don't get what I mean, once again post the complete source code
of your radio button list which is not working as expected (aspx part
and code-behind) and explain how it should work step by step.
 
R

rcoco

This is how the code looks like:

private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
Fill();
Bind();
}
}
System.Web.UI.WebControls.RadioButtonList st5=new
System.Web.UI.WebControls.RadioButtonList();
st5=(System.Web.UI.WebControls.RadioButtonList)e.Item.Cells[1].FindControl("rblmood");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into DashBoard (MoodToday) values
(@MoodToday)";
myCommand.Parameters.Add(new
SqlParameter("@MoodToday",SqlDbType.Text));
myCommand.Parameters["@MoodToday"].Value=st5.SelectedValue;
if(st5.SelectedValue=="Bad Mood")
{
st5.SelectedValue="images/sad.gif";
}
else if(st5.SelectedValue=="Good Mood")
{
st5.SelectedValue="images/laughing.gif";
}
Fill();
InsertEmpty();
Bind();
This is the HTML part
<ItemTemplate>
<asp:Label id=Label2 runat="server" Width="104px" text='<%#
DataBinder.Eval(Container,"DataItem.MoodToday")%>'>Label</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/laughing.gif"
ImageAlign="Right"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"
ImageAlign="Right"></asp:Image>
</EditItemTemplate>
Thanks
 
R

rcoco

This how it is supposed to work.
When a user selects RadioButton GoodMood the image imggm(laughing.gif)
should be selected as well.
and if BadMood is selected Image imgbm it should be imgbm(sad.gif).
Thanks.
 
G

Guest

This how it is supposed to work.
When a user selects RadioButton GoodMood the image imggm(laughing.gif)
should be selected as well.
and if BadMood is selected Image imgbm it should be imgbm(sad.gif).
Thanks.

What do you mean by "the image should be selected"?

Assuming the code is working properly, except a "selection" of the
image, you should change the if..else block

Image imggm = (Image)e.Item.Cells[1].FindControl("imggm");
Image imgbm = (Image)e.Item.Cells[1].FindControl("imgbm");

if (st5.SelectedValue == "Bad Mood")
{
imgbm.BorderWidth = Unit.Pixel(2);
} else {
imggm.BorderWidth = Unit.Pixel(2);
}

This code put a border around the first image if st5.SelectedValue !=
"Bad Mood", otherwise, the second image will be bordered. This is how
I understand your "selection".

Hope, it helps.
 
R

rcoco

Hi,
Lets say this is any of the image: ))(( .
What I'm trying is to get the out put look like: ))(( Good Mood
after inserting data In a datagrid cell for right now after inserting
data I only get Good Mood. with out the Image.
As You see in the html code The Image and RadioButtonList are in
EditItemTemplate:

<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="112px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/
laughing.gif"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"></
asp:Image>
</EditItemTemplate>

Thanks
 
G

Guest

Hi,
Lets say this is any of the image: ))(( .
What I'm trying is to get the out put look like: ))(( Good Mood
after inserting data In a datagrid cell for right now after inserting
data I only get Good Mood. with out the Image.
As You see in the html code The Image and RadioButtonList are in
EditItemTemplate:

<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="112px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/
laughing.gif"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"></
asp:Image>
</EditItemTemplate>

Thanks

I don't get your reply.

What problem do you have? An image sad.gif is not shown? If yes, when
the problem occurs, when page is initially loaded or after you changed
a selection of the RadioButtonList?
 
R

rcoco

I don't get your reply.

What problem do you have? An image sad.gif is not shown? If yes, when
the problem occurs, when page is initially loaded or after you changed
a selection of the RadioButtonList?- Hide quoted text -

- Show quoted text -

It's supposed to work like this When on selection of RadioButton from
RadioButtonList and inserts data that is when Image should be visible
in datagrid column. For example if Bad Mood is selected and inserted
into database, image sad.gif should be visible in datagrid column:
))(( Bad Mood (consider ))(( to be image sad.gif).
This should be after one has inserted data.
Thanks
Thanks.
 
R

rcoco

It's supposed to work like this When on selection of RadioButton from
RadioButtonList and inserts data that is when Image should be visible
in datagrid column. For example if Bad Mood is selected and inserted
into database, image sad.gif should be visible in datagrid column:
))(( Bad Mood (consider ))(( to be image sad.gif).
This should be after one has inserted data.
Thanks
Thanks.- Hide quoted text -

- Show quoted text -

Alexey,
What if I Change the images from EditItemTemplate to ItemTemplate
wouldn't it be better? As in I make the images invisible and When I
edit my data in datagrid one of the images becomes visible can tha
work?
Thanks
 
G

Guest

It's supposed to work like this When on selection of RadioButton from
RadioButtonList and inserts data that is when Image should be visible
in datagrid column. For example if Bad Mood is selected and inserted
into database, image sad.gif should be visible in datagrid column:
))(( Bad Mood (consider ))(( to be image sad.gif).
This should be after one has inserted data.
Thanks
Thanks.- Hide quoted text -

- Show quoted text -

But then I think it has nothing to do with the EditItemTemplate

If I understand you correct, you have to change

<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/
laughing.gif"
ImageAlign="Right"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"
ImageAlign="Right"></asp:Image>
</EditItemTemplate>

to:

<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
</EditItemTemplate>

and delete the following part

if(st5.SelectedValue=="Bad Mood")
{
st5.SelectedValue="images/sad.gif";
}
else if(st5.SelectedValue=="Good Mood")
{
st5.SelectedValue="images/laughing.gif";
}

The EditItemTemplate used to edit a current record in the datagrid.

That is:

1) you bind your grid to the database
2) you show EditItemTemplate with your radio buttons
3) you post the web form back to the server
4) you find a selected value of the radio button

<-- I guess, you are this step

5) you save the selected value to a database
6) you bind your grid to the database again

So, you should update the database (step #5) and repeat step #1 which
is the same to step #6

How to with a DataGrid
http://www.google.com/search?hl=en&q=datagrid+tutorial+asp.net
 
R

rcoco

But then I think it has nothing to do with the EditItemTemplate

If I understand you correct, you have to change

<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
<asp:Image id="imggm" runat="server" ImageUrl="../Images/
laughing.gif"
ImageAlign="Right"></asp:Image>
<asp:Image id="imgbm" runat="server" ImageUrl="../Images/sad.gif"
ImageAlign="Right"></asp:Image>
</EditItemTemplate>

to:

<EditItemTemplate>
<asp:RadioButtonList id="rblmood" runat="server" Width="104px">
<asp:ListItem Value="Good Mood">Good Mood</asp:ListItem>
<asp:ListItem Value="Bad Mood">Bad Mood</asp:ListItem>
</asp:RadioButtonList>
</EditItemTemplate>

and delete the following part

if(st5.SelectedValue=="Bad Mood")
{
st5.SelectedValue="images/sad.gif";}

else if(st5.SelectedValue=="Good Mood")
{
st5.SelectedValue="images/laughing.gif";

}

The EditItemTemplate used to edit a current record in the datagrid.

That is:

1) you bind your grid to the database
2) you show EditItemTemplate with your radio buttons
3) you post the web form back to the server
4) you find a selected value of the radio button

<-- I guess, you are this step

5) you save the selected value to a database
6) you bind your grid to the database again

So, you should update the database (step #5) and repeat step #1 which
is the same to step #6

How to with a DataGridhttp://www.google.com/search?hl=en&q=datagrid+tutorial+asp.net- Hide quoted text -

- Show quoted text -

But after updating the datagrid how can I make one I mage visible?
Thnks
 
G

Guest

But after updating the datagrid how can I make one I mage visible?
Thnks- Hide quoted text -

You are right, I forgot to mention.

You can have an additional column in your datagrid, where you will
show your "mood".

I'm not sure what exactly you kept in the database as a "mood" value:
a string, or numeric value?

If you kept a string in the database ("sad", or "laughing")

the code will be

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
DataBinder.Eval(Container.DataItem, "Mood") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>

where Mood is a name of your datasource field

If you save your mood as a numeric value (e.g. "0" - for sad, "1" -
for "laughing")

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
((int)DataBinder.Eval(Container.DataItem, "Mood") == 0 ? "sad" :
"laughing") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>
 
R

rcoco

You are right, I forgot to mention.

You can have an additional column in your datagrid, where you will
show your "mood".

I'm not sure what exactly you kept in the database as a "mood" value:
a string, or numeric value?

If you kept a string in the database ("sad", or "laughing")

the code will be

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
DataBinder.Eval(Container.DataItem, "Mood") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>

where Mood is a name of your datasource field

If you save your mood as a numeric value (e.g. "0" - for sad, "1" -
for "laughing")

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
((int)DataBinder.Eval(Container.DataItem, "Mood") == 0 ? "sad" :
"laughing") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>

Seems not working I'm i getting it right?
<ItemTemplate>
<asp:Label id=Label2 runat="server" Width="97px" text='<%#
DataBinder.Eval(Container,"DataItem.MoodToday")%>'>Label</asp:Label>
<asp:Image id=imgbm runat="server" ImageUrl='<%# "/Images/"
+DataBinder.Eval(Container.DataItem, "MoodToday") + "../Images/
sad.gif"%>' Visible="False">
</asp:Image>
<asp:Image id=imggm runat="server" ImageUrl='<%# "/Images/"
+DataBinder.Eval(Container.DataItem, "MoodToday") + "../images/
laughing.gif"%>' Visible="False">
</asp:Image>
</ItemTemplate>
Thanks
 
G

Guest

Seems not working I'm i getting it right?
<ItemTemplate>
<asp:Label id=Label2 runat="server" Width="97px" text='<%#
DataBinder.Eval(Container,"DataItem.MoodToday")%>'>Label</asp:Label>
<asp:Image id=imgbm runat="server" ImageUrl='<%# "/Images/"
+DataBinder.Eval(Container.DataItem, "MoodToday") + "../Images/
sad.gif"%>' Visible="False">
</asp:Image>
<asp:Image id=imggm runat="server" ImageUrl='<%# "/Images/"
+DataBinder.Eval(Container.DataItem, "MoodToday") + "../images/
laughing.gif"%>' Visible="False">
</asp:Image>
</ItemTemplate>
Thanks- Hide quoted text -

- Show quoted text -


ImageUrl='<%# "/Images/" +DataBinder.Eval(Container.DataItem,
"MoodToday") + "../Images/sad.gif"%>'

Using the code above, what URL are you expecting to get in the output?
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top