Thursday, March 29, 2012
Newbie: Image button aspect ratio
problems so far...
However, when it loads the image using IMAGEURL=, it doesn't keep the
original aspect ratio.
Is there a way to keep this without resizing the control?
Many thanks,
David Whitchurch-BennettThe aspect ratio is not affected at all by the ImageURL property. Most
likely you have the height or width of the control set to a value. If you
remove those values from the control, the image will come in at its normal
size, if you want it smaller (but wish to preserve the aspect ratio), then
just set a width or a height for the control but not both.
"David Whitchurch-Bennett"
<DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
news:11381908-84A6-467F-99A3-B274561AA68D@.microsoft.com...
>I have some image buttons which I am dynamically adding from a database. No
> problems so far...
> However, when it loads the image using IMAGEURL=, it doesn't keep the
> original aspect ratio.
> Is there a way to keep this without resizing the control?
> Many thanks,
> David Whitchurch-Bennett
>
Thanks for that information. What I have in my app is an image button set to
250 x 250, with a thick border which is all part of the visual theme. That i
s
why I have set the size first. What I want to do is load an image dynamicall
y
in the center of the image button, but keep the image button border the same
size, so the visual theme is preserved.
Is this possible, or will the only way be to place the image button into
another container with a border.
"Scott M." wrote:
> The aspect ratio is not affected at all by the ImageURL property. Most
> likely you have the height or width of the control set to a value. If you
> remove those values from the control, the image will come in at its normal
> size, if you want it smaller (but wish to preserve the aspect ratio), then
> just set a width or a height for the control but not both.
> "David Whitchurch-Bennett"
> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
> news:11381908-84A6-467F-99A3-B274561AA68D@.microsoft.com...
>
>
I think this is more of an issue of having graphics that will fit into a
250x250 space that VS.NET sizing the images for you. Your best bet is to
use a good graphics tool to create images that will fit into that space,
rather than attempt to have VS.NET fit them for you.
"David Whitchurch-Bennett"
<DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
news:B4825793-D8BD-476C-96B8-9E63062C1B6F@.microsoft.com...
> Thanks for that information. What I have in my app is an image button set
> to
> 250 x 250, with a thick border which is all part of the visual theme. That
> is
> why I have set the size first. What I want to do is load an image
> dynamically
> in the center of the image button, but keep the image button border the
> same
> size, so the visual theme is preserved.
> Is this possible, or will the only way be to place the image button into
> another container with a border.
> "Scott M." wrote:
>
I already have this. I am using a class that I have written to scale down th
e
image first for two reasons.
1. To help the page load faster.
2. To prevent people downloading the full size images (photographic website)
.
Rather than resizing all of my photos, my class takes care of this by
scaling down the image. I pass the maximum width and height, and the image i
s
scaled down to fit and it maintains the aspect ratio.
When I put the scaled down image into the button, it stetches it out to fit
in both dimensions.
I guess I just asumed there would be a way to display the image without
stretching it out. I can pad the extra pixels in the function to return a
square image if that is a better way.
Thanks for your help. ASP.NET is quite different to what I am used to, but I
am getting there!
"Scott M." wrote:
> I think this is more of an issue of having graphics that will fit into a
> 250x250 space that VS.NET sizing the images for you. Your best bet is to
> use a good graphics tool to create images that will fit into that space,
> rather than attempt to have VS.NET fit them for you.
> "David Whitchurch-Bennett"
> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
> news:B4825793-D8BD-476C-96B8-9E63062C1B6F@.microsoft.com...
>
>
How about putting the image into an image control (not a button image
control) and overlaying the image control on top of your button control?
"David Whitchurch-Bennett"
<DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
news:C9567572-5BBC-4DE9-83C9-44BE4F3465F4@.microsoft.com...
>I already have this. I am using a class that I have written to scale down
>the
> image first for two reasons.
> 1. To help the page load faster.
> 2. To prevent people downloading the full size images (photographic
> website).
> Rather than resizing all of my photos, my class takes care of this by
> scaling down the image. I pass the maximum width and height, and the image
> is
> scaled down to fit and it maintains the aspect ratio.
> When I put the scaled down image into the button, it stetches it out to
> fit
> in both dimensions.
> I guess I just asumed there would be a way to display the image without
> stretching it out. I can pad the extra pixels in the function to return a
> square image if that is a better way.
> Thanks for your help. ASP.NET is quite different to what I am used to, but
> I
> am getting there!
> "Scott M." wrote:
>
I ran into the same problem... I found an easy to solution to prevent scalin
g is to use a hyperlink control and set its imageurl property to the image i
n question.
Newbie: Image button aspect ratio
problems so far...
However, when it loads the image using IMAGEURL=, it doesn't keep the
original aspect ratio.
Is there a way to keep this without resizing the control?
Many thanks,
David Whitchurch-BennettThe aspect ratio is not affected at all by the ImageURL property. Most
likely you have the height or width of the control set to a value. If you
remove those values from the control, the image will come in at its normal
size, if you want it smaller (but wish to preserve the aspect ratio), then
just set a width or a height for the control but not both.
"David Whitchurch-Bennett"
<DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
news:11381908-84A6-467F-99A3-B274561AA68D@.microsoft.com...
>I have some image buttons which I am dynamically adding from a database. No
> problems so far...
> However, when it loads the image using IMAGEURL=, it doesn't keep the
> original aspect ratio.
> Is there a way to keep this without resizing the control?
> Many thanks,
> David Whitchurch-Bennett
Thanks for that information. What I have in my app is an image button set to
250 x 250, with a thick border which is all part of the visual theme. That is
why I have set the size first. What I want to do is load an image dynamically
in the center of the image button, but keep the image button border the same
size, so the visual theme is preserved.
Is this possible, or will the only way be to place the image button into
another container with a border.
"Scott M." wrote:
> The aspect ratio is not affected at all by the ImageURL property. Most
> likely you have the height or width of the control set to a value. If you
> remove those values from the control, the image will come in at its normal
> size, if you want it smaller (but wish to preserve the aspect ratio), then
> just set a width or a height for the control but not both.
> "David Whitchurch-Bennett"
> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
> news:11381908-84A6-467F-99A3-B274561AA68D@.microsoft.com...
> >I have some image buttons which I am dynamically adding from a database. No
> > problems so far...
> > However, when it loads the image using IMAGEURL=, it doesn't keep the
> > original aspect ratio.
> > Is there a way to keep this without resizing the control?
> > Many thanks,
> > David Whitchurch-Bennett
>
I think this is more of an issue of having graphics that will fit into a
250x250 space that VS.NET sizing the images for you. Your best bet is to
use a good graphics tool to create images that will fit into that space,
rather than attempt to have VS.NET fit them for you.
"David Whitchurch-Bennett"
<DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
news:B4825793-D8BD-476C-96B8-9E63062C1B6F@.microsoft.com...
> Thanks for that information. What I have in my app is an image button set
> to
> 250 x 250, with a thick border which is all part of the visual theme. That
> is
> why I have set the size first. What I want to do is load an image
> dynamically
> in the center of the image button, but keep the image button border the
> same
> size, so the visual theme is preserved.
> Is this possible, or will the only way be to place the image button into
> another container with a border.
> "Scott M." wrote:
>> The aspect ratio is not affected at all by the ImageURL property. Most
>> likely you have the height or width of the control set to a value. If
>> you
>> remove those values from the control, the image will come in at its
>> normal
>> size, if you want it smaller (but wish to preserve the aspect ratio),
>> then
>> just set a width or a height for the control but not both.
>>
>> "David Whitchurch-Bennett"
>> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
>> news:11381908-84A6-467F-99A3-B274561AA68D@.microsoft.com...
>> >I have some image buttons which I am dynamically adding from a database.
>> >No
>> > problems so far...
>>> > However, when it loads the image using IMAGEURL=, it doesn't keep the
>> > original aspect ratio.
>>> > Is there a way to keep this without resizing the control?
>>> > Many thanks,
>>> > David Whitchurch-Bennett
>>>
>>
>
I already have this. I am using a class that I have written to scale down the
image first for two reasons.
1. To help the page load faster.
2. To prevent people downloading the full size images (photographic website).
Rather than resizing all of my photos, my class takes care of this by
scaling down the image. I pass the maximum width and height, and the image is
scaled down to fit and it maintains the aspect ratio.
When I put the scaled down image into the button, it stetches it out to fit
in both dimensions.
I guess I just asumed there would be a way to display the image without
stretching it out. I can pad the extra pixels in the function to return a
square image if that is a better way.
Thanks for your help. ASP.NET is quite different to what I am used to, but I
am getting there!
"Scott M." wrote:
> I think this is more of an issue of having graphics that will fit into a
> 250x250 space that VS.NET sizing the images for you. Your best bet is to
> use a good graphics tool to create images that will fit into that space,
> rather than attempt to have VS.NET fit them for you.
> "David Whitchurch-Bennett"
> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
> news:B4825793-D8BD-476C-96B8-9E63062C1B6F@.microsoft.com...
> > Thanks for that information. What I have in my app is an image button set
> > to
> > 250 x 250, with a thick border which is all part of the visual theme. That
> > is
> > why I have set the size first. What I want to do is load an image
> > dynamically
> > in the center of the image button, but keep the image button border the
> > same
> > size, so the visual theme is preserved.
> > Is this possible, or will the only way be to place the image button into
> > another container with a border.
> > "Scott M." wrote:
> >> The aspect ratio is not affected at all by the ImageURL property. Most
> >> likely you have the height or width of the control set to a value. If
> >> you
> >> remove those values from the control, the image will come in at its
> >> normal
> >> size, if you want it smaller (but wish to preserve the aspect ratio),
> >> then
> >> just set a width or a height for the control but not both.
> >>
> >> "David Whitchurch-Bennett"
> >> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
> >> news:11381908-84A6-467F-99A3-B274561AA68D@.microsoft.com...
> >> >I have some image buttons which I am dynamically adding from a database.
> >> >No
> >> > problems so far...
> >> >> > However, when it loads the image using IMAGEURL=, it doesn't keep the
> >> > original aspect ratio.
> >> >> > Is there a way to keep this without resizing the control?
> >> >> > Many thanks,
> >> >> > David Whitchurch-Bennett
> >> >>
> >>
> >>
>
How about putting the image into an image control (not a button image
control) and overlaying the image control on top of your button control?
"David Whitchurch-Bennett"
<DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
news:C9567572-5BBC-4DE9-83C9-44BE4F3465F4@.microsoft.com...
>I already have this. I am using a class that I have written to scale down
>the
> image first for two reasons.
> 1. To help the page load faster.
> 2. To prevent people downloading the full size images (photographic
> website).
> Rather than resizing all of my photos, my class takes care of this by
> scaling down the image. I pass the maximum width and height, and the image
> is
> scaled down to fit and it maintains the aspect ratio.
> When I put the scaled down image into the button, it stetches it out to
> fit
> in both dimensions.
> I guess I just asumed there would be a way to display the image without
> stretching it out. I can pad the extra pixels in the function to return a
> square image if that is a better way.
> Thanks for your help. ASP.NET is quite different to what I am used to, but
> I
> am getting there!
> "Scott M." wrote:
>> I think this is more of an issue of having graphics that will fit into a
>> 250x250 space that VS.NET sizing the images for you. Your best bet is to
>> use a good graphics tool to create images that will fit into that space,
>> rather than attempt to have VS.NET fit them for you.
>>
>> "David Whitchurch-Bennett"
>> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
>> news:B4825793-D8BD-476C-96B8-9E63062C1B6F@.microsoft.com...
>> > Thanks for that information. What I have in my app is an image button
>> > set
>> > to
>> > 250 x 250, with a thick border which is all part of the visual theme.
>> > That
>> > is
>> > why I have set the size first. What I want to do is load an image
>> > dynamically
>> > in the center of the image button, but keep the image button border the
>> > same
>> > size, so the visual theme is preserved.
>>> > Is this possible, or will the only way be to place the image button
>> > into
>> > another container with a border.
>>> > "Scott M." wrote:
>>> >> The aspect ratio is not affected at all by the ImageURL property.
>> >> Most
>> >> likely you have the height or width of the control set to a value. If
>> >> you
>> >> remove those values from the control, the image will come in at its
>> >> normal
>> >> size, if you want it smaller (but wish to preserve the aspect ratio),
>> >> then
>> >> just set a width or a height for the control but not both.
>> >>
>> >> "David Whitchurch-Bennett"
>> >> <DavidWhitchurchBennett@.discussions.microsoft.com> wrote in message
>> >> news:11381908-84A6-467F-99A3-B274561AA68D@.microsoft.com...
>> >> >I have some image buttons which I am dynamically adding from a
>> >> >database.
>> >> >No
>> >> > problems so far...
>> >>> >> > However, when it loads the image using IMAGEURL=, it doesn't keep
>> >> > the
>> >> > original aspect ratio.
>> >>> >> > Is there a way to keep this without resizing the control?
>> >>> >> > Many thanks,
>> >>> >> > David Whitchurch-Bennett
>> >>> >>
>> >>
>> >>
>>
>>
>
Saturday, March 24, 2012
Newbie: switch control
switch value with button in the page (below failig test code).
I know in this test case I could create an extra variable and use it, my
problem is the switch, i my real problem is in a repeater, hence I cannot
use a property!
how to change the label of the galador:Switch?
--
<script runat="server">
void OnSwapSwitch(object sender, EventArgs e)
{
switch (mySwitch.Value)
{
case "0":
mySwitch.Value = "1";
break;
default:
mySwitch.Value = "0";
break;
}
}
</script>
<galador:Switch id=mySwitch runat=server Value=1 >
<galador:SwitchCase runat=server label=0>
Azerty
<asp:LinkButton ID="LinkButton1" Runat=server
OnClick=OnSwapSwitch >Clic
Clac</asp:LinkButton>
</galador:SwitchCase>
<galador:SwitchCase runat=server label=1>
Qwerty
<asp:LinkButton ID="LinkButton2" Runat=server
OnClick=OnSwapSwitch >Kodak</asp:LinkButton>
</galador:SwitchCase>
</galador:Switch>Have you tried to databind your value to some variable? For example, when
you switch, in your back-end code, if you set some variable ( string MyVar =
"";), then do a Page.DataBind(), then you can access it in your ascx/aspx
code using something like this... <galador:SwitchCase runat=server
label="<%= MyVar %>">
Would that work for you?
Alex
"Lloyd Dupont" <ld@.NewsAccount.galador.net> wrote in message
news:uxC$yS%23wEHA.3416@.TK2MSFTNGP09.phx.gbl...
> I try to create a switch control, but I'm hitting a problem, changing the
> switch value with button in the page (below failig test code).
> I know in this test case I could create an extra variable and use it, my
> problem is the switch, i my real problem is in a repeater, hence I cannot
> use a property!
> how to change the label of the galador:Switch?
> --
> <script runat="server">
> void OnSwapSwitch(object sender, EventArgs e)
> {
> switch (mySwitch.Value)
> {
> case "0":
> mySwitch.Value = "1";
> break;
> default:
> mySwitch.Value = "0";
> break;
> }
> }
> </script>
> <galador:Switch id=mySwitch runat=server Value=1 >
> <galador:SwitchCase runat=server label=0>
> Azerty
> <asp:LinkButton ID="LinkButton1" Runat=server
> OnClick=OnSwapSwitch >Clic
> Clac</asp:LinkButton>
> </galador:SwitchCase>
> <galador:SwitchCase runat=server label=1>
> Qwerty
> <asp:LinkButton ID="LinkButton2" Runat=server
> OnClick=OnSwapSwitch >Kodak</asp:LinkButton>
> </galador:SwitchCase>
> </galador:Switch>
>
well, I guess I will have too...
but what I wonder is, my switch is in a repeater, how could I store the
value in a variable?
"Alex" <Alex@.donotemailme.com> wrote in message
news:uE1nVCGxEHA.1984@.TK2MSFTNGP14.phx.gbl...
> Have you tried to databind your value to some variable? For example, when
> you switch, in your back-end code, if you set some variable ( string MyVar
> =
> "";), then do a Page.DataBind(), then you can access it in your ascx/aspx
> code using something like this... <galador:SwitchCase runat=server
> label="<%= MyVar %>">
> Would that work for you?
> --
> Alex
> "Lloyd Dupont" <ld@.NewsAccount.galador.net> wrote in message
> news:uxC$yS%23wEHA.3416@.TK2MSFTNGP09.phx.gbl...
>
Newbie: switch control
switch value with button in the page (below failig test code).
I know in this test case I could create an extra variable and use it, my
problem is the switch, i my real problem is in a repeater, hence I cannot
use a property!
how to change the label of the galador:Switch?
----------
<script runat="server">
void OnSwapSwitch(object sender, EventArgs e)
{
switch (mySwitch.Value)
{
case "0":
mySwitch.Value = "1";
break;
default:
mySwitch.Value = "0";
break;
}
}
</script
<galador:Switch id=mySwitch runat=server Value=1
<galador:SwitchCase runat=server label=0>
Azerty
<asp:LinkButton ID="LinkButton1" Runat=server
OnClick=OnSwapSwitch >Clic
Clac</asp:LinkButton>
</galador:SwitchCase
<galador:SwitchCase runat=server label=1>
Qwerty
<asp:LinkButton ID="LinkButton2" Runat=server
OnClick=OnSwapSwitch >Kodak</asp:LinkButton>
</galador:SwitchCase
</galador:SwitchHave you tried to databind your value to some variable? For example, when
you switch, in your back-end code, if you set some variable ( string MyVar =
"";), then do a Page.DataBind(), then you can access it in your ascx/aspx
code using something like this... <galador:SwitchCase runat=server
label="<%= MyVar %>"
Would that work for you?
--
Alex
"Lloyd Dupont" <ld@.NewsAccount.galador.net> wrote in message
news:uxC$yS%23wEHA.3416@.TK2MSFTNGP09.phx.gbl...
> I try to create a switch control, but I'm hitting a problem, changing the
> switch value with button in the page (below failig test code).
> I know in this test case I could create an extra variable and use it, my
> problem is the switch, i my real problem is in a repeater, hence I cannot
> use a property!
> how to change the label of the galador:Switch?
> ----------
> <script runat="server">
> void OnSwapSwitch(object sender, EventArgs e)
> {
> switch (mySwitch.Value)
> {
> case "0":
> mySwitch.Value = "1";
> break;
> default:
> mySwitch.Value = "0";
> break;
> }
> }
> </script>
> <galador:Switch id=mySwitch runat=server Value=1 >
> <galador:SwitchCase runat=server label=0>
> Azerty
> <asp:LinkButton ID="LinkButton1" Runat=server
> OnClick=OnSwapSwitch >Clic
> Clac</asp:LinkButton>
> </galador:SwitchCase>
> <galador:SwitchCase runat=server label=1>
> Qwerty
> <asp:LinkButton ID="LinkButton2" Runat=server
> OnClick=OnSwapSwitch >Kodak</asp:LinkButton>
> </galador:SwitchCase>
> </galador:Switch>
well, I guess I will have too...
but what I wonder is, my switch is in a repeater, how could I store the
value in a variable?
"Alex" <Alex@.donotemailme.com> wrote in message
news:uE1nVCGxEHA.1984@.TK2MSFTNGP14.phx.gbl...
> Have you tried to databind your value to some variable? For example, when
> you switch, in your back-end code, if you set some variable ( string MyVar
> =
> "";), then do a Page.DataBind(), then you can access it in your ascx/aspx
> code using something like this... <galador:SwitchCase runat=server
> label="<%= MyVar %>">
> Would that work for you?
> --
> Alex
> "Lloyd Dupont" <ld@.NewsAccount.galador.net> wrote in message
> news:uxC$yS%23wEHA.3416@.TK2MSFTNGP09.phx.gbl...
>> I try to create a switch control, but I'm hitting a problem, changing the
>> switch value with button in the page (below failig test code).
>>
>> I know in this test case I could create an extra variable and use it, my
>> problem is the switch, i my real problem is in a repeater, hence I cannot
>> use a property!
>>
>> how to change the label of the galador:Switch?
>> ----------
>> <script runat="server">
>> void OnSwapSwitch(object sender, EventArgs e)
>> {
>> switch (mySwitch.Value)
>> {
>> case "0":
>> mySwitch.Value = "1";
>> break;
>> default:
>> mySwitch.Value = "0";
>> break;
>> }
>> }
>> </script>
>>
>> <galador:Switch id=mySwitch runat=server Value=1 >
>>
>> <galador:SwitchCase runat=server label=0>
>> Azerty
>> <asp:LinkButton ID="LinkButton1" Runat=server
>> OnClick=OnSwapSwitch >Clic
>> Clac</asp:LinkButton>
>> </galador:SwitchCase>
>>
>> <galador:SwitchCase runat=server label=1>
>> Qwerty
>> <asp:LinkButton ID="LinkButton2" Runat=server
>> OnClick=OnSwapSwitch >Kodak</asp:LinkButton>
>> </galador:SwitchCase>
>>
>> </galador:Switch>
>>
>>
Thursday, March 22, 2012
Newbie-Index out of range error
I am trying to get my update button to function from my datagrid. But I
keep getting a index out of range error. I see this post alot, and now I'm
proabably more confused about tha ever. When I hit my edit button, it loads
the right fields into my textboxes, there I can change the info, then hit
save. But then the error pop's up. Now I can add a new record with out any
problem. I do not have a textbox for my ID column, which is my key.
To my understanding, it's not reading the "key" column properly.
I guess i'm not sure what I'm looking for. what would be the line of code
that would cause this problem, or what areas may I look at to make sure I
have it set up right. For all I know, I may not even have the right line of
code in there.
I tried the EditItemIndex = e.item thing, but I'm not sure where to put it.
I'm sorry I don't have my code with me right now, but I can post later
tonite if needed. I know it makes it alot easier to figure out.
As always, thanks!
RudyRudy,
I think it's probably best to post your code. The error typically means
you're trying to update a row (item) but the index or row positions that
you've set is greater than the total number of rows.
Jon
"Rudy" wrote:
> Hello all!
> I am trying to get my update button to function from my datagrid. But I
> keep getting a index out of range error. I see this post alot, and now I'm
> proabably more confused about tha ever. When I hit my edit button, it loads
> the right fields into my textboxes, there I can change the info, then hit
> save. But then the error pop's up. Now I can add a new record with out any
> problem. I do not have a textbox for my ID column, which is my key.
> To my understanding, it's not reading the "key" column properly.
> I guess i'm not sure what I'm looking for. what would be the line of code
> that would cause this problem, or what areas may I look at to make sure I
> have it set up right. For all I know, I may not even have the right line of
> code in there.
> I tried the EditItemIndex = e.item thing, but I'm not sure where to put it.
> I'm sorry I don't have my code with me right now, but I can post later
> tonite if needed. I know it makes it alot easier to figure out.
> As always, thanks!
> Rudy
Hi Jon!
Here is the code that I have.
Private Sub SaveItem()
Dim strSQL As String
If btnSave.CommandArgument = "Add" Then
strSQL = _
"INSERT INTO IMSProducts " & _
" (ProductName, SupplierPart, UnitCost, UnitsInStock, " & _
" Discontinued, UnitSRP, Used) " & _
"VALUES " & _
" (@.ProductName, @.SupplierPart, @.UnitCost, @.UnitsInStock,
" & _
" @.Discontinued, @.UnitSRP, @.Used)"
Else ' The user is updating an existing item.
strSQL = _
"UPDATE IMSProducts " & _
"SET ProductName = @.ProductName, " & _
" SupplierPart = @.SupplierPart, " & _
" UnitSRP = @.UnitSRP, " & _
" UnitCost = @.UnitCost, " & _
" UnitsInStock = @.UnitsInStock, " & _
" Discontinued = @.Discontinued, " & _
" Used = @.Used " & _
"WHERE ProductID = @.ProductID"
End If
Dim Sqlconnection1 As New SqlConnection(SQL_CONNECTION_STRING)
Dim scmd As New SqlCommand(strSQL, Sqlconnection1)
' Add all the required SQL parameters.
With scmd.Parameters
' The ProductID parameter is only needed for updating.
If btnSave.CommandArgument <> "Add" Then
.Add(New SqlParameter("@.ProductID", _
SqlDbType.Int)).Value = _
CInt(grdProducts.DataKeys(grdProducts.SelectedInde x).ToString)
' grdProducts.EditItemIndex = -1
End If
.Add(New SqlParameter("@.ProductName", _
SqlDbType.NVarChar, 40)).Value = txtProductName.Text
.Add(New SqlParameter("@.SupplierPart", _
SqlDbType.NVarChar, 50)).Value = txtSupplier.Text
.Add(New SqlParameter("@.UnitCost", _
SqlDbType.Money)).Value = CDbl(txtCost.Text)
.Add(New SqlParameter("@.UnitSRP", _
SqlDbType.Money)).Value = CDbl(txtSRP.Text)
.Add(New SqlParameter("@.UnitsInStock", _
SqlDbType.Int)).Value = CInt(txtInStock.Text)
.Add(New SqlParameter("@.Discontinued", _
SqlDbType.Bit)).Value = chkDiscontinued.Checked
'.Add(New SqlParameter("@.New", _
' SqlDbType.Bit)).Value = chkNew.Checked
.Add(New SqlParameter("@.Used", _
SqlDbType.Bit)).Value = chkUsed.Checked
End With
Try
Sqlconnection1.Open()
scmd.ExecuteNonQuery()
Cache.Remove("dvProducts")
BindProductsGrid()
strMsg = "Your a star! Product successfully saved to the
database."
pnlForm.Visible = True
Catch exp As Exception
strErrorMsg = "Database error! Product not saved to the " & _
"database. Error message: " & exp.Message
Finally
Sqlconnection1.Close()
End Try
End Sub
Here is the code for the save btn.
' This routine handles the "Save Changes" button Click event.
Private Sub btnSave_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSave.Click
If IsValid Then
SaveItem()
txtProductName.Text = ""
txtSupplier.Text = ""
txtCost.Text = ""
txtSRP.Text = ""
txtInStock.Text = ""
chkDiscontinued.Checked = False
chkUsed.Checked = False
End If
End Sub
I hope this makes a little more sense.
Thank you for your time!!
Rudy
"Jon" wrote:
> Rudy,
> I think it's probably best to post your code. The error typically means
> you're trying to update a row (item) but the index or row positions that
> you've set is greater than the total number of rows.
> Jon
> "Rudy" wrote:
> > Hello all!
> > I am trying to get my update button to function from my datagrid. But I
> > keep getting a index out of range error. I see this post alot, and now I'm
> > proabably more confused about tha ever. When I hit my edit button, it loads
> > the right fields into my textboxes, there I can change the info, then hit
> > save. But then the error pop's up. Now I can add a new record with out any
> > problem. I do not have a textbox for my ID column, which is my key.
> > To my understanding, it's not reading the "key" column properly.
> > I guess i'm not sure what I'm looking for. what would be the line of code
> > that would cause this problem, or what areas may I look at to make sure I
> > have it set up right. For all I know, I may not even have the right line of
> > code in there.
> > I tried the EditItemIndex = e.item thing, but I'm not sure where to put it.
> > I'm sorry I don't have my code with me right now, but I can post later
> > tonite if needed. I know it makes it alot easier to figure out.
> > As always, thanks!
> > Rudy
Newbies Question on data variables
sth, and return some data to the same page. The problem is I have a public
variable, say tmpA in C# in which data will set while the first button is
clicked. I need to get the value of tmpA when pressing other button, the
problem is how can I save the value of tmpA?
Do I need to add a hidden field on the form to do that?
Or is there any better approach? ThanksAre you asking how to preserve variables between postbacks? If this is what
you mean, put them in the VewState:
int tempA;
...
ViewState["TEMPA"] = tempA;
...
tempA = (int)ViewState["TEMPA"];
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
"Vivian" <wkichu@.hotmail.comwrote in message
news:e69UdhWpGHA.4988@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
>I have an aspx page with C# with several "post" button. Each button will do
>sth, and return some data to the same page. The problem is I have a public
>variable, say tmpA in C# in which data will set while the first button is
>clicked. I need to get the value of tmpA when pressing other button, the
>problem is how can I save the value of tmpA?
Do I need to add a hidden field on the form to do that?
Or is there any better approach? Thanks
>
Thanks. That's what I need.
"Eliyahu Goldin" <removemeegoldin@.monarchmed.comglsD:uVtA7 RYpGHA.4268@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
Are you asking how to preserve variables between postbacks? If this is
what you mean, put them in the VewState:
>
int tempA;
...
ViewState["TEMPA"] = tempA;
...
tempA = (int)ViewState["TEMPA"];
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
>
"Vivian" <wkichu@.hotmail.comwrote in message
news:e69UdhWpGHA.4988@.TK2MSFTNGP04.phx.gbl...
Quote:
Originally Posted by
>>I have an aspx page with C# with several "post" button. Each button will
>>do sth, and return some data to the same page. The problem is I have a
>>public variable, say tmpA in C# in which data will set while the first
>>button is clicked. I need to get the value of tmpA when pressing other
>>button, the problem is how can I save the value of tmpA?
>Do I need to add a hidden field on the form to do that?
>Or is there any better approach? Thanks
>>
>
>
Newby question RE transfering data between pages.
I am hoping that this is a simple problem. I have a page that has a button the code for that button is as follows.
protectedvoid btnServerSearch_Click(object sender,EventArgs e)
{
string scriptStr ="<script type=text/javascript>window.open('FrmLoanSelect.aspx',null,'height=400,width=650');</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(),"Pop", scriptStr);
txLoanNumber.Text = (string)Session["DaData"];
}
When I click the button the new page displays beautifully in a window, in the dimensions that I requests. The code that is setting the session variable "DaData" is in the page being displayed as follows.
protectedvoid GridView1_SelectedIndexChanged(object sender,EventArgs e)
{
Session["DaData"] = GridView1.Rows[GridView1.SelectedIndex].Cells[1].Text;
}
The problem appears to be that the main form is not waiting on the form it just displayed and therefore the session variable doesnt exist yet. Is there some way to make the main form wait for the exit of the popup form ? Or am I going to have to find some other way of passing the data from the popup form ?
Any input that anyone has is mughty appreciated!!
Bump for the non-weekend crowd.Hi,
The solution lies in using Modal Pop ups.
I have put together a small example for you.
In the calling (main page) use a client script to open up a modal window.
Main Page Code Behind
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Attributes.Add("onClick", "ShowPop();");
}
protected void Button1_Click(object sender, EventArgs e)
{
string x= (string)Session["X"];
}
}
javascript:
function ShowPop()
{
var win = window.showModalDialog('PopUpWindow.aspx', '', 'dialogHeight: 200px; dialogWidth: 300px; help: No; resizable: No; status: No;');
}
Called Page, Pop Up. Code Behind
ublic partial class PopUpWindow : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["X"] = TextBox1.Text;
string scriptStr = "<script type=text/javascript>window.close();</script>";
ClientScript.RegisterClientScriptBlock(this.GetType(), "Pop", scriptStr);
}
}
This way, ur main page calls a popup, the pop up sets a value in session and closes itself( all this while the main page is still active)
The main page button on click gets invoked and it can access the value set in session
lemme know if this helps.
Deepak.
Thank you very much for the response!!
I think that I am 90% of the way there. The better news is that I managed to learn a LOT from your post :) I finally grasped that you can add client side event handlers to a server control using the attribute.add method.
That problem that I am encountering now is, I think, insurmountable, at least it seems that way to me. I am displaying a grid in my popup window, and when ever I select an entry in the grid, or try to select a different page on the grid its doing a postback, and that is giving me an error. The error details ( as seen in the Internet Explorer Error box ) Line: 1 Char: 1 Error: Object Expected Code: 0 URL: javascript:__doPostBack('GridView1','Page$6'). This specific error message was displayed when I tried to swap to page 6 of the gridview. When I try to select a specific value in the grid the message changes in the URL: portion to URL: javascript:__doPostBack('GridView1','Select$7').
This though makes sense to me that I am getting these errors, as I am trying to do a postback on a form that I specifically invoked as Modal. If I am wrong in this and Ive missed somthing I would love to hear it!
Once again thank you greatly for the help!!
Vince Campanile
A few things to look for:
1) Make sure you do not have any javascript syntax errors
2)If the script is in diff file, make sure you have included the src in ur script declaration
If you can paste ur code template, I can try to see the issue.
From a first glance looks like its lookin for a function and its not finding it...
HTH
Deepak.
Not sure what your refering to when you ask about the script. Do you mean the Script thats actually calling the modalDialog ?
Here is the entirety of the window that I am creating, with the exception that I have redacted out the database information
<%@. Page Language="C#" AutoEventWireup="true" CodeBehind="FrmLoanSelect.aspx.cs" Inherits="BrokeredLoans.FrmLoanSelect" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Select Loan</title></head><body> <form id="form1" runat="server"> <div> <asp:GridView ID="gvLoanSelections" runat="server" AutoGenerateColumns="False" DataKeyNames="loanMasterID" DataSourceID="dsLoanSelect" Height="138px" Width="638px" AllowPaging="True" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" OnSelectedIndexChanged="gvLoanSelections_SelectedIndexChanged"> <Columns> <asp:CommandField ShowSelectButton="True" /> <asp:BoundField DataField="loanNumber" HeaderText="Loan Number" SortExpression="loanNumber" /> <asp:BoundField DataField="borrowerFirstName" HeaderText="First Name" SortExpression="borrowerFirstName" /> <asp:BoundField DataField="borrowerLastName" HeaderText="Last Name" SortExpression="borrowerLastName" /> <asp:BoundField DataField="fundedDate" HeaderText="Funded Date" SortExpression="fundedDate" /> </Columns> <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /> <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /> <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /> <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /> <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /> </asp:GridView> </div> </form></body></html>
Here is the code behind page that is for that web page.
namespace BrokeredLoans{public partialclass FrmLoanSelect : System.Web.UI.Page {protected void gvLoanSelections_SelectedIndexChanged(object sender, EventArgs e) { Session["DaData"] = gvLoanSelections.Rows[gvLoanSelections.SelectedIndex].Cells[1].Text;string scriptStr ="<script type=text/javascript>window.close();</script>"; ClientScript.RegisterClientScriptBlock(this.GetType(),"Pop", scriptStr); } }}The code that is calling the popup is as follows.
<script type="text/jscript"> function ShowPopup() { var win = window.showModalDialog('FrmLoanSelect.aspx','','dialogHeight=400,dialogWidth=725,resizable: No;status: No'); }</script>Thank you so much for taking the time out to help this newby along! :)
Another little tidbit of information...
I added another button to just plain show the search screen and when I make a selection there, or change the page no error is encountered and the search screen closes itsself like it should.
So as far as I can tell its somthing to do with the showl ShowModalDialog call.
Put <base target="_self" /> in the <head> ... </head> section of the page to be displayed in the modal window
You can make use of cross post back
=========
Cross-Page Posting
One common feature in ASP 3.0 that is difficult to achieve in ASP.NET 1.0/1.1 is the capability to do
cross-page posting. Cross-page posting enables you to submit a form (say,Page1.aspx) and have thisform and all the control values post themselves to another page (Page2.aspx).Traditionally, any page created in ASP.NET 1.0/1.1 simply posted to itself, and you handled the control
values within this page instance. You could differentiate between the page's first request and any postbacks
by using thePage.IsPostBackproperty, as shown here:
If Page.IsPostBack Then
' deal with control values
End If
Even with this capability, many developers still wanted to be able to post to another page and deal with
the first page's control values on that page. This is now possible in ASP.NET 2.0, and it is quite a simple
process.
For an example, create a page calledPage1.aspxthat contains a simple form. This page is shown in<title>First Page</title>
</head>
<body>
<form id="form1" runat="server">
Enter your name:<br />
<asp:Textbox ID="TextBox1" Runat="server">
</asp:Textbox>
<p>
When do you want to fly?<br />
<asp:Calendar ID="Calendar1" Runat="server"></asp:Calendar></p>
<br />
<asp:Button ID="Button1" Runat="server" Text="Submit page to itself"
OnClick="Button1_Click" />
<asp:Button ID="Button2" Runat="server" Text="Submit page to Page2.aspx"
PostBackUrl="Page2.aspx" />
<p>
<asp:Label ID="Label1" Runat="server"></asp:Label></p>
</form>
</body>
</html>
C#
<%@. Page Language="C#" %>
<script runat="server">
protected void Button1_Click (object sender, System.EventArgs e)
{
Label1.Text = "Hello " + TextBox1.Text + "<br />" +
"Date Selected: " + Calendar1.SelectedDate.ToShortDateString();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
protected void Page_Load(object sender, System.EventArgs e)
{
TextBox pp_Textbox1;
Calendar pp_Calendar1;
pp_Textbox1 = (TextBox)PreviousPage.FindControl("Textbox1");
pp_Calendar1 = (Calendar)PreviousPage.FindControl("Calendar1");
Label1.Text = "Hello " + pp_Textbox1.Text + "<br />" + "Date Selected: " +
pp_Calendar1.SelectedDate.ToShortDateString();
}
</script>