Saturday, March 31, 2012
Triggering event, listbox
listbox I have on a page. I'm able to populate the listbox with data from a
stored procedure, but cannot trigger the event. I do have EnableViewState =
True for the listbox. I'm imagining (wanting) to populate the listbox named:
lstNames by using the DataValueField from lstDepartments.
It's quite apparent though that the event is not triggering as I can misname
the stored procedure and no error occurs.
Here is the code, I'm sure it will wrap terribly however::
MGSurvey.aspx:
<FORM id="MGSurvey" runat="server">
<p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
<asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION: relative;
TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged =
"lstDepartments_SelectedIndexChanged" Width="258px"
Height="118px"></asp:listbox>
<asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION: relative"
runat="server" Width="559px" Height="144px" BackColor="Transparent"
BorderColor="Transparent">
<asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
relative; TOP: 20px" runat="server" Width="258px" EnableViewState="True"
BackColor="Transparent"></asp:listbox>
</asp:panel>
</p>
</FORM>
MGSurvey.aspx.vb:
Public Sub lstDepartments_SelectedIndexChanged(ByVa
l sender As Object, ByVal
e As EventArgs)
If (Not IsPostBack) Then
adoConn.Open()
Dim adoCommDeptMembers As New SqlCommand("dbo.MG_EmployeesByDepartment "
& lstDepartments.SelectedItem.Value, adoConn)
With lstNames
.DataSource =
adoCommDeptMembers.ExecuteReader(CommandBehavior.CloseConnection)
.DataTextField = "Name"
.DataValueField = "tp_ID"
.DataBind()
End With
adoConn.Close()
End If
End SubHow is the user triggering a postback to the server?
What happens when the page posts back to the server? What does it all look
like?
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
news:ez4PuKNrFHA.260@.TK2MSFTNGP11.phx.gbl...
> For some reason I cannot get the OnSelectedIndexChanged event to fire for
> a
> listbox I have on a page. I'm able to populate the listbox with data from
> a
> stored procedure, but cannot trigger the event. I do have EnableViewState
> =
> True for the listbox. I'm imagining (wanting) to populate the listbox
> named:
> lstNames by using the DataValueField from lstDepartments.
> It's quite apparent though that the event is not triggering as I can
> misname
> the stored procedure and no error occurs.
> Here is the code, I'm sure it will wrap terribly however::
> MGSurvey.aspx:
> <FORM id="MGSurvey" runat="server">
> <p style="Z-INDEX: 101; LEFT: 15px; POSITION: relative">
> <asp:listbox id="lstDepartments" style="Z-INDEX: 102; POSITION: relative;
> TOP: 6px" runat="server" EnableViewState="true" OnSelectedIndexChanged =
> "lstDepartments_SelectedIndexChanged" Width="258px"
> Height="118px"></asp:listbox>
> <asp:panel id="pnDepartmentMembers" style="Z-INDEX: 103; POSITION:
> relative"
> runat="server" Width="559px" Height="144px" BackColor="Transparent"
> BorderColor="Transparent">
> <asp:listbox id="lstNames" style="Z-INDEX: 103; LEFT: 15px; POSITION:
> relative; TOP: 20px" runat="server" Width="258px" EnableViewState="True"
> BackColor="Transparent"></asp:listbox>
> </asp:panel>
> </p>
> </FORM>
> MGSurvey.aspx.vb:
> Public Sub lstDepartments_SelectedIndexChanged(ByVa
l sender As Object,
> ByVal
> e As EventArgs)
> If (Not IsPostBack) Then
> adoConn.Open()
> Dim adoCommDeptMembers As New SqlCommand("dbo.MG_EmployeesByDepartment
> "
> & lstDepartments.SelectedItem.Value, adoConn)
> With lstNames
> .DataSource =
> adoCommDeptMembers.ExecuteReader(CommandBehavior.CloseConnection)
> .DataTextField = "Name"
> .DataValueField = "tp_ID"
> .DataBind()
> End With
> adoConn.Close()
> End If
> End Sub
>
Well, I have two listboxes.
lstDepartments - Lists Departments
lstNames - Lists Members of Departments
On Page Load lstDepartments is loaded with a list of departments, with the
department 'code' as the DataValueField.
What I want to happen is, when you click on an item in the list of
departments, lstNames gets populated with the members of that department.
Stored procedures worked, tested them, they have the proper permissions,
etc.
Just can't seem to get OnSelectedIndexChanged to fire...I've tried with 'Not
IsPostBack' and without it...not sure how else to answer your
question...thanks! :)
"Marina" <someone@.nospam.com> wrote in message
news:erppRNNrFHA.3720@.TK2MSFTNGP14.phx.gbl...
> How is the user triggering a postback to the server?
> What happens when the page posts back to the server? What does it all look
> like?
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:ez4PuKNrFHA.260@.TK2MSFTNGP11.phx.gbl...
for
from
EnableViewState
relative;
SqlCommand("dbo.MG_EmployeesByDepartment
>
You didn't really answer my questions at all, so I'm sorry but I don't have
any ideas on how to help you.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
> Well, I have two listboxes.
> lstDepartments - Lists Departments
> lstNames - Lists Members of Departments
> On Page Load lstDepartments is loaded with a list of departments, with the
> department 'code' as the DataValueField.
> What I want to happen is, when you click on an item in the list of
> departments, lstNames gets populated with the members of that department.
> Stored procedures worked, tested them, they have the proper permissions,
> etc.
> Just can't seem to get OnSelectedIndexChanged to fire...I've tried with
> 'Not
> IsPostBack' and without it...not sure how else to answer your
> question...thanks! :)
> "Marina" <someone@.nospam.com> wrote in message
> news:erppRNNrFHA.3720@.TK2MSFTNGP14.phx.gbl...
> for
> from
> EnableViewState
> relative;
> SqlCommand("dbo.MG_EmployeesByDepartment
>
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e listbox named lstDepartments.
"What happens when the page posts back to the server? What does it all look
like?" - Nothing happens, the first listbox flickers when you select an item
, and the second listbox remains empty, and no error message occurs.
"Marina" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
>
>
Ok, so the problem is that there is no postback to the server!
A server side event can't run, unless something forces a postback to the ser
ver. Your page is sitting in the browser - whatever objects the server used
to generate the page are long gone. HTTP is a connectionless protocol - it'
s just the browser on its own.
So you need something there to trigger an event to the server.
I think the listbox may be one of the objects that has an AutoPostback prope
rty. If it does, setting this to True, will trigger a postback to the server
whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback
. It may be that there is a button the user has to click to proceed, or you
may have to write some javascript to trigger the post.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e listbox named lstDepartments.
"What happens when the page posts back to the server? What does it all look
like?" - Nothing happens, the first listbox flickers when you select an item
, and the second listbox remains empty, and no error message occurs.
"Marina" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
>
>
Well I'll be damned...that worked! Thank you!
For future reference...when would I not want to do a postback, and if 90% of
the time people do postback, why isn't it the default behavior? I would hav
e gnashed my teeth over that one indefinately...
"Marina" <someone@.nospam.com> wrote in message news:O6YP1gNrFHA.528@.TK2MSFTN
GP09.phx.gbl...
Ok, so the problem is that there is no postback to the server!
A server side event can't run, unless something forces a postback to the ser
ver. Your page is sitting in the browser - whatever objects the server used
to generate the page are long gone. HTTP is a connectionless protocol - it'
s just the browser on its own.
So you need something there to trigger an event to the server.
I think the listbox may be one of the objects that has an AutoPostback prope
rty. If it does, setting this to True, will trigger a postback to the server
whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback
. It may be that there is a button the user has to click to proceed, or you
may have to write some javascript to trigger the post.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e listbox named lstDepartments.
"What happens when the page posts back to the server? What does it all look
like?" - Nothing happens, the first listbox flickers when you select an item
, and the second listbox remains empty, and no error message occurs.
"Marina" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
>
>
Because, who is to say that you always want a postback?
A lot of times, a user is filling out a form, and has many fields to fill ou
t. Then they hit 'Submit', and go to the next page. In this case you would
not want to postback automatically. Not only because there is nothing to do
until the form is filled out, but because it is a waste of resources, and l
ooks ugly with the screen flashing all the time.
So I would say, that it is not the case that people want to postback most of
the time. It really just depends on the type of application and what the UI
needs to do.
I think most people would assume that nothing happens by default, because th
at is what HTML equivalents of these controls would do. And then they add c
ode to change the default behavior.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:OFaBqoNrF
HA.2624@.TK2MSFTNGP15.phx.gbl...
Well I'll be damned...that worked! Thank you!
For future reference...when would I not want to do a postback, and if 90% of
the time people do postback, why isn't it the default behavior? I would hav
e gnashed my teeth over that one indefinately...
"Marina" <someone@.nospam.com> wrote in message news:O6YP1gNrFHA.528@.TK2MSFTN
GP09.phx.gbl...
Ok, so the problem is that there is no postback to the server!
A server side event can't run, unless something forces a postback to the ser
ver. Your page is sitting in the browser - whatever objects the server used
to generate the page are long gone. HTTP is a connectionless protocol - it'
s just the browser on its own.
So you need something there to trigger an event to the server.
I think the listbox may be one of the objects that has an AutoPostback prope
rty. If it does, setting this to True, will trigger a postback to the server
whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback
. It may be that there is a button the user has to click to proceed, or you
may have to write some javascript to trigger the post.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e listbox named lstDepartments.
"What happens when the page posts back to the server? What does it all look
like?" - Nothing happens, the first listbox flickers when you select an item
, and the second listbox remains empty, and no error message occurs.
"Marina" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
>
>
I appreciate the great explanation. Thank you.
"Marina" <someone@.nospam.com> wrote in message news:uQjFnrNrFHA.2880@.TK2MSFT
NGP12.phx.gbl...
Because, who is to say that you always want a postback?
A lot of times, a user is filling out a form, and has many fields to fill ou
t. Then they hit 'Submit', and go to the next page. In this case you would
not want to postback automatically. Not only because there is nothing to do
until the form is filled out, but because it is a waste of resources, and l
ooks ugly with the screen flashing all the time.
So I would say, that it is not the case that people want to postback most of
the time. It really just depends on the type of application and what the UI
needs to do.
I think most people would assume that nothing happens by default, because th
at is what HTML equivalents of these controls would do. And then they add c
ode to change the default behavior.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:OFaBqoNrF
HA.2624@.TK2MSFTNGP15.phx.gbl...
Well I'll be damned...that worked! Thank you!
For future reference...when would I not want to do a postback, and if 90% of
the time people do postback, why isn't it the default behavior? I would hav
e gnashed my teeth over that one indefinately...
"Marina" <someone@.nospam.com> wrote in message news:O6YP1gNrFHA.528@.TK2MSFTN
GP09.phx.gbl...
Ok, so the problem is that there is no postback to the server!
A server side event can't run, unless something forces a postback to the ser
ver. Your page is sitting in the browser - whatever objects the server used
to generate the page are long gone. HTTP is a connectionless protocol - it'
s just the browser on its own.
So you need something there to trigger an event to the server.
I think the listbox may be one of the objects that has an AutoPostback prope
rty. If it does, setting this to True, will trigger a postback to the server
whenever the selected item is changed.
If the listbox does not have such a property, you need to trigger a postback
. It may be that there is a button the user has to click to proceed, or you
may have to write some javascript to trigger the post.
"Steve Schroeder" <sschroeder@.somewhere.com> wrote in message news:e0RNqcNrF
HA.1128@.TK2MSFTNGP11.phx.gbl...
"How is the user triggering a postback to the server?" - Postback, as I unde
rstand it is triggered by reloading the page. In my case, this is not happen
ing. All the user should be doing is selecting with their mouse and item in
the listbox, and hopefully triggering the OnSelectedIndexChanged event of th
e listbox named lstDepartments.
"What happens when the page posts back to the server? What does it all look
like?" - Nothing happens, the first listbox flickers when you select an item
, and the second listbox remains empty, and no error message occurs.
"Marina" <someone@.nospam.com> wrote in message news:uJuQVWNrFHA.3444@.TK2MSFTNGP12.phx.gbl..
.
> You didn't really answer my questions at all, so I'm sorry but I don't hav
e
> any ideas on how to help you.
>
> "Steve Schroeder" <sschroeder@.somewhere.com> wrote in message
> news:u0gIWTNrFHA.2768@.TK2MSFTNGP12.phx.gbl...
>
>
Triggering ItemCommand with ImageButton in Datagrid
I had a Delete Column in a datagrid that was a Linkbutton. That needed to
change into a ImageButton because of the design demands in the project. Then
how do I trigger the DeleteCommand with that button?
I don't want to have to add a AddHandler in the ItemCreated or ItemDataBound
for this ImageButton cause then I can't get the ID from the Row to delete as
easy...
please help/
Lars NetzelSpecify the ImageButton with CommandName="Delete" attribute.
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../
CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
and Update correspond to the same action with the DataGrid (DataGrid has
these command names predefined for cthese actions)
See docs for further details.
--
Teemu Keiski
ASP.NET MVP, Finland
"Lars Netzel" <uihsdf@.adf.se> wrote in message
news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
> Hi
> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
> change into a ImageButton because of the design demands in the project.
> Then how do I trigger the DeleteCommand with that button?
> I don't want to have to add a AddHandler in the ItemCreated or
> ItemDataBound for this ImageButton cause then I can't get the ID from the
> Row to delete as easy...
> please help/
> Lars Netzel
Ah, stupid me:) I wrote ItemCommand instead of CommandName... thx
/Lars
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message
news:eHCfx26LFHA.3988@.tk2msftngp13.phx.gbl...
> Specify the ImageButton with CommandName="Delete" attribute.
> <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
> CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
> and Update correspond to the same action with the DataGrid (DataGrid has
> these command names predefined for cthese actions)
> See docs for further details.
> --
> Teemu Keiski
> ASP.NET MVP, Finland
> "Lars Netzel" <uihsdf@.adf.se> wrote in message
> news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
>> Hi
>>
>> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
>> change into a ImageButton because of the design demands in the project.
>> Then how do I trigger the DeleteCommand with that button?
>>
>> I don't want to have to add a AddHandler in the ItemCreated or
>> ItemDataBound for this ImageButton cause then I can't get the ID from the
>> Row to delete as easy...
>>
>> please help/
>> Lars Netzel
>>
Triggering ItemCommand with ImageButton in Datagrid
I had a Delete Column in a datagrid that was a Linkbutton. That needed to
change into a ImageButton because of the design demands in the project. Then
how do I trigger the DeleteCommand with that button?
I don't want to have to add a AddHandler in the ItemCreated or ItemDataBound
for this ImageButton cause then I can't get the ID from the Row to delete as
easy...
please help/
Lars NetzelSpecify the ImageButton with CommandName="Delete" attribute.
<asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
and Update correspond to the same action with the DataGrid (DataGrid has
these command names predefined for cthese actions)
See docs for further details.
Teemu Keiski
ASP.NET MVP, Finland
"Lars Netzel" <uihsdf@.adf.se> wrote in message
news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
> Hi
> I had a Delete Column in a datagrid that was a Linkbutton. That needed to
> change into a ImageButton because of the design demands in the project.
> Then how do I trigger the DeleteCommand with that button?
> I don't want to have to add a AddHandler in the ItemCreated or
> ItemDataBound for this ImageButton cause then I can't get the ID from the
> Row to delete as easy...
> please help/
> Lars Netzel
>
Ah, stupid me:) I wrote ItemCommand instead of CommandName... thx
/Lars
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message
news:eHCfx26LFHA.3988@.tk2msftngp13.phx.gbl...
> Specify the ImageButton with CommandName="Delete" attribute.
> <asp:ImageButton ID="btnDelete" runat="server" CommandName="Delete" .../>
> CommandNames Cancel, Delete, Edit, NextPage, Page, PrevPage, Select, Sort
> and Update correspond to the same action with the DataGrid (DataGrid has
> these command names predefined for cthese actions)
> See docs for further details.
> --
> Teemu Keiski
> ASP.NET MVP, Finland
> "Lars Netzel" <uihsdf@.adf.se> wrote in message
> news:%23edWRq6LFHA.3328@.TK2MSFTNGP14.phx.gbl...
>
triggering SQLDATASOURCE insert or update command programatically?
of the button with commandname=insert or insert?
I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.
Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.
Thanks.Hi,
Have you tried calling the Insert method of the sqldatasource directly, it
should do what you want
Regards,
Mohamed Mosalem
http://mosalem.blogspot.com
"Jason" wrote:
> Is there any way to initiate a sqldatasource insert from code in place
> of the button with commandname=insert or insert?
> I have a formview with a datasource with an insert command on a
> button. When the button is selected the insert is performed.
> Say I have another button on the form with no command syntax that calls
> a some sub. Is there any way to call the same sqldatasource insert
> function from code? in debug when I look at the onclick sub that I am
> calling when the insert button is pressed, i see all the properties of
> the button, like commandname=insert, but that sub is not the real deal
> and is infact not even doing anything.
> Thanks.
>
somebody else suggested that so I tried it, but when I do that for some
reason it does not see bound fields. I had two buttons up, one calling
a sub that did what you suggested and another with no code behind doing
commandname=insert and the only the later would work.
Mohamed Mosalem wrote:
> Hi,
> Have you tried calling the Insert method of the sqldatasource directly, it
> should do what you want
> Regards,
> Mohamed Mosalem
> http://mosalem.blogspot.com
> "Jason" wrote:
>
triggering SQLDATASOURCE insert or update command programatically?
of the button with commandname=insert or insert?
I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.
Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.
Thanks.Hi,
Have you tried calling the Insert method of the sqldatasource directly, it
should do what you want
Regards,
Mohamed Mosalem
http://mosalem.blogspot.com
"Jason" wrote:
Quote:
Originally Posted by
Is there any way to initiate a sqldatasource insert from code in place
of the button with commandname=insert or insert?
>
I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.
>
Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.
>
Thanks.
>
>
somebody else suggested that so I tried it, but when I do that for some
reason it does not see bound fields. I had two buttons up, one calling
a sub that did what you suggested and another with no code behind doing
commandname=insert and the only the later would work.
Mohamed Mosalem wrote:
Quote:
Originally Posted by
Hi,
Have you tried calling the Insert method of the sqldatasource directly, it
should do what you want
>
Regards,
Mohamed Mosalem
http://mosalem.blogspot.com
>
"Jason" wrote:
>
Quote:
Originally Posted by
Is there any way to initiate a sqldatasource insert from code in place
of the button with commandname=insert or insert?
I have a formview with a datasource with an insert command on a
button. When the button is selected the insert is performed.
Say I have another button on the form with no command syntax that calls
a some sub. Is there any way to call the same sqldatasource insert
function from code? in debug when I look at the onclick sub that I am
calling when the insert button is pressed, i see all the properties of
the button, like commandname=insert, but that sub is not the real deal
and is infact not even doing anything.
Thanks.
triggers
STOCK_ITEM
Barcode
Description
Price
Quantity_on_Order
Quantity_in_Stock
SEASONAL
Barcode
Season
Start_Date
End_Date
I want to use a trigger to delete one row out of SEASONAL when one row out
of STOCK_ITEM is deleted. The primary keys of the two rows that are to be
deleted must be the same.
Can you please tell me what is the code for the trigger?
Thanks,
Wally.>> I have two tables (STOCK_ITEM and SEASONAL):...<<
How about using a Cascading Delete...
-- Code
CREATE TABLE StockItems
(
Barcode varchar(20) PRIMARY KEY,
Description varchar(20) NOT NULL,
Price smallmoney NOT NULL,
Quantity_on_Order smallint NULL,
Quantity_in_Stock smallint NOT NULL
);
INSERT StockItems VALUES ('123456789','cool product',11.95,1,10);
CREATE TABLE Seasons
(
SeasonID smallint PRIMARY KEY,
Barcode varchar(20) FOREIGN KEY REFERENCES StockItems(Barcode) ON DELETE
CASCADE,
Season varchar(10) NOT NULL,
Start_Date smalldatetime NOT NULL,
End_Date smalldatetime NOT NULL,
);
INSERT Seasons VALUES (1,'123456789','summer','06/23/06','09/22/06');
DELETE StockItems WHERE Barcode = '123456789';
SELECT COUNT(*) FROM Seasons;
-- results --
0
-- End of Code
Garth
www.SQLBook.com
triggers
STOCK_ITEM
Barcode
Description
Price
Quantity_on_Order
Quantity_in_Stock
SEASONAL
Barcode
Season
Start_Date
End_Date
I want to use a trigger to delete one row out of SEASONAL when one row out
of STOCK_ITEM is deleted. The primary keys of the two rows that are to be
deleted must be the same.
Can you please tell me what is the code for the trigger?
Thanks,
Wally.>> I have two tables (STOCK_ITEM and SEASONAL):...<<
How about using a Cascading Delete...
-- Code
CREATE TABLE StockItems
(
Barcode varchar(20) PRIMARY KEY,
Description varchar(20) NOT NULL,
Price smallmoney NOT NULL,
Quantity_on_Order smallint NULL,
Quantity_in_Stock smallint NOT NULL
);
INSERT StockItems VALUES ('123456789','
CREATE TABLE Seasons
(
SeasonID smallint PRIMARY KEY,
Barcode varchar(20) FOREIGN KEY REFERENCES StockItems(Barcode) ON DELETE
CASCADE,
Season varchar(10) NOT NULL,
Start_Date smalldatetime NOT NULL,
End_Date smalldatetime NOT NULL,
);
INSERT Seasons VALUES (1,'123456789','summer','06/23/06','09/22/06');
DELETE StockItems WHERE Barcode = '123456789';
SELECT COUNT(*) FROM Seasons;
-- results --
0
-- End of Code
Garth
www.SQLBook.com
trim
ie
<Value>123456 </Value
thanks
markif you merely use Trim(value)
or myVar.Trim
--
this will assure you have no white space at either end
Hi,
TryString.Trim Method
HTH
Trim a DB field
<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 5,1) %> with a number of 675432 the result would be 3. With a number of 75432 the result would be 2. I need them always be in the 2 spot even if my field has a 7, 6, 5, or 4 digit numbers in it.
This is trimming the ListNum field in my database down to one number. When the database field is 6 numbers long it works perfectly. If the database number is 5 numbers long it selects the last number instead of the 2nd to the last number. Is there a way to get the trim command to count the numbers from the right and not the left. So the code would look something like this.
<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 2,1) %>
Thanks for any help.Try something like this:
Dim myString as string
myString = DataSet1.FieldValue("ListNum", Container).Trim()
myString = myString.Substring(myString.Length-2, 1)
The code is a section out of much more.. Here is the code all together.
<img src="http://pics.10026.com/?src=http://photos.neg.ctimls.com/neg/photos/small/<%# Mid(DataSet1.FieldValue("ListNum", Container).Trim(), 5,1) %>/<%# Right(DataSet1.FieldValue("ListNum", Container).Trim(), 1) %>/<%# DataSet1.FieldValue("ListNum", Container) %>a.jpg" width="100" alt="">
Because it is a piece of a code that is why I can't use something like that. Also there are many of these for one page on the site so I have to keep it as simple as possible.
Thanks
Trim array of null object
ArrayList alArray = new ArrayList();for ( int i = 0; i < myArray.Length; ++i )
{
if ( myArray[i] != null )
alArray.Add(myArray[i]);
}
Or maybe, if you want to remove null value objects:
for ( int i = 0; i < myArrayList.Length; i++ )
{
if (myArrayList[i] == null )
myArrayList.RemoveAt[i]);
}
The ArrayList is in many ways extremely practical, as you don't have to redim the size. You just simply remove the unwanted elements.
Trim and Substring?
That is put into a dataset b/c of the following Dataset (which I had a lot of help on b/c I'm still lost on Cast). However I'm just curious if anyone knows How I can pull this # out thanks.
CREATE PROCEDURE dbo.sp_Goals_GetPlantGoalsReviewPage
@dotnet.itags.org.CompanyID nvarchar(2), @dotnet.itags.org.FacilityID nvarchar(2)
AS
DECLARE @dotnet.itags.org.StartMonth int, @dotnet.itags.org.EndMonth int
SELECT @dotnet.itags.org.StartMonth = StartMonth, @dotnet.itags.org.EndMonth = EndMonth FROM Period WHERE PeriodID = dbo.fn_GetCurrentPeriod(@dotnet.itags.org.CompanyID, @dotnet.itags.org.FacilityID)
DECLARE @dotnet.itags.org.Column nvarchar(1000)
DECLARE @dotnet.itags.org.i int
SET @dotnet.itags.org.i = @dotnet.itags.org.StartMonth
SET @dotnet.itags.org.Column = 'Cast(GoalMByte' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + ' AS int)'
WHILE @dotnet.itags.org.i < @dotnet.itags.org.EndMonth
BEGIN
SET @dotnet.itags.org.i = @dotnet.itags.org.i + 1
SET @dotnet.itags.org.Column = @dotnet.itags.org.Column + ' + Cast(GoalMByte' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + ' AS int)'
END
DECLARE @dotnet.itags.org.Query nvarchar(2000)
SET @dotnet.itags.org.Query = ('SELECT [Description] + '' - '' + Cast(Points AS nvarchar(100)) + '' Points - ('' + Cast(' + @dotnet.itags.org.Column + ' AS nvarchar(100)) +''/' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + ')'' AS PlantGoals,Points ,' + @dotnet.itags.org.Column + '/' + Cast(@dotnet.itags.org.i AS nvarchar(100)) + 'AS Fraction
FROM Goals
WHERE CompanyID = ''' + @dotnet.itags.org.CompanyID + ''' AND FacilityID = ''' + @dotnet.itags.org.FacilityID + ''' AND PeriodID = ' + Cast(dbo.fn_GetCurrentPeriod(@dotnet.itags.org.CompanyID, @dotnet.itags.org.FacilityID) AS nvarchar(100)) + ' AND GoalCategory = ''Plant''')
EXEC (@dotnet.itags.org.Query)lets say you create a string that contains the whole string from the DB
dim strAll as string = DBRecord 'Assuming output will be something like: Yeild - 15 Points - (3/6)
Now you can tokenize the string into 3 distinct parts (Yield , 15 points, and (3/6) )
dim strTokens as string() = strAll.split("-"c)
Now to reference the (3/6) portion you can:
dim strFoo as string = strTokens(2)
Now you can split, trim all you like with just that part. :)
Sweet thanks -- I'll give it a shot.
i couldn't tell from your post if the '-' character was a hyphen or a minus sign if its a minus, (ie part of the data) split based on " " the space character
worked great thanks!
trim and pure apparently whitespace strings
mouse-over) that when TRIM'd does not result in a null-string ?
how to determine any special characters that may be present in the string ?trimming a string with just spaces will return an empty string ("") not a
null string (null)...
The easiest way to evaluate the string would be to write it to disk. Create
a file and write the string out, then analyse the file in a hex editor to
check for excape characters.
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> has anyone encountered an apparently pure whitespace string (debug mode
> mouse-over) that when TRIM'd does not result in a null-string ?
> how to determine any special characters that may be present in the string
> ?
i was using "null-string" in the traditional sense of a reference to a
String datatype object that consists of 0 characters -- not a
"null-reference" (a reference to Nothing)
actually, i found this very useful function for discovering hidden
characters in a string:
Uri.HexEscape()
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:OAfw44H0EHA.2600@.TK2MSFTNGP09.phx.gbl...
> trimming a string with just spaces will return an empty string ("") not a
> null string (null)...
> The easiest way to evaluate the string would be to write it to disk.
Create
> a file and write the string out, then analyse the file in a hex editor to
> check for excape characters.
>
> "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> > has anyone encountered an apparently pure whitespace string (debug mode
> > mouse-over) that when TRIM'd does not result in a null-string ?
> > how to determine any special characters that may be present in the
string
> > ?
trim and pure apparently whitespace strings
mouse-over) that when TRIM'd does not result in a null-string ?
how to determine any special characters that may be present in the string ?trimming a string with just spaces will return an empty string ("") not a
null string (null)...
The easiest way to evaluate the string would be to write it to disk. Create
a file and write the string out, then analyse the file in a hex editor to
check for excape characters.
"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
> has anyone encountered an apparently pure whitespace string (debug mode
> mouse-over) that when TRIM'd does not result in a null-string ?
> how to determine any special characters that may be present in the string
> ?
>
i was using "null-string" in the traditional sense of a reference to a
String datatype object that consists of 0 characters -- not a
"null-reference" (a reference to Nothing)
actually, i found this very useful function for discovering hidden
characters in a string:
Uri.HexEscape()
"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:OAfw44H0EHA.2600@.TK2MSFTNGP09.phx.gbl...
> trimming a string with just spaces will return an empty string ("") not a
> null string (null)...
> The easiest way to evaluate the string would be to write it to disk.
Create
> a file and write the string out, then analyse the file in a hex editor to
> check for excape characters.
>
> "John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
> news:eFtfjQG0EHA.1264@.TK2MSFTNGP12.phx.gbl...
string
>
Trim all characters after the first " . " help need...
I need a really basic line of code which i can not find. I need to do is remove ALL characters after and inc the characters "." found in a variable. i have a variable which holds device with DNS name such as E096064-FWSM2.netdevice.companyname.com i want the variable to just hold the name E096064-FWSM2 the extension after the first "." can very greatly so i can not specify all possible options as i just do not know what they are going to be.
really hope someone can help me
paul
code below did the job
DNSnode = Left(fullDNSname, InStr(fullDNSname, ".")-1)
trim a URL link through datagrid
Hi,
Is there anyway I can trim this URL?
The Output is something like this:http://www.test.com/default.aspx?siteid=1&pagetitle=this_is_a_test and I want to get rid of everything past "?" so it just showshttp://www.test.com/default.aspx
This is the code i am using to get the URL through a datagrid in C#: 'Navigate='<%# Databinder.Eval(Container.DataItem, "LinkPath") %>' How can I trim this URL in the backend?
Thanks for anyone that can help me out.
Hi
Hope this helps
//Create a method calledstring GetTrimmedURL(string CompleteURL){ string TrimmedURL = String.Empty; string str = CompleteURL;int intIndexOfchar = str.IndexOf("?"); TrimmedURL = str.substring(intIndexOfchar, (str.Length() - intIndexOfchar));return TrimmedURL;}Call this method at the place where you are doing the data binding. Say something like
'Navigate='<%# GetTrimmedURL(Databinder.Eval(Container.DataItem, "LinkPath")) %>'
Please note that this trims from the first instance of question mark though.
Hope this helps
Note: Pls watch out for small syntactical errors. Did this on a notepad.
VJ
Hi
You can do the following to strip the querystring off the URL:
Uri linkPath =new Uri(YOUROBJECTHERE.LinkPath);string newLinkPath = linkPath.Scheme + "://" + linkPath.Host + linkPath.AbsolutePath;
You could either do this is in the class you are databinding to, or perhaps in an OnItemDataBound event handler on your DataGrid, depending on your preference.
Hope this helps.
Seb
Trim Each textbox control - Repost
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
------------------------
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
------------------------
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Can you help?
Many Thanks!
AlexHi,
here is an example how to loop through controls on the Page:
http://www.aspnet101.com/aspnet101/tips.aspx?id=97
If you want to access Text property, you need to have typed reference (cast
it to TextBox with CType and set the value to the property).
--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke
"Alex Shirley" <postings@.alexshirley.com> wrote in message
news:e9704b08.0406280400.238ba501@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> The problem I have is not really with the trim function. It's the fact
> that I cannot update the control text value. It won't allow the .text
> property at all in this example because "thiscontrol" is not actually
> aware that the control assigned to it is actually a textbox. Is there a
> way to tell it it's a textbox so I can access this property, or is there
> another way around this?
>
> Can you help?
> Many Thanks!
> Alex
Thanks Teemu
However I'm still stuck with the casting the object I've discovered in
a for next loop to a textbox so I can access its properties in
VB/ASP.Net... dumb I know, but I've looked everywhere for an answer,
but obviously not in the right places!
So far I've got this code:
-----------
Dim ThisControl As System.Web.UI.Control
Dim txtControl As TextBox
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
txtControl = CType(ThisControl, TextBox) ' am I casting this
correctly?
txtControl.Text = "I'vechanged" 'Doesn't work
End If
Next ThisControl
-----------
I tried ThisControl = CType(ThisControl, TextBox), but the properties
won't appear for thiscontrol.
Sorry but can you or somebody help in this casting so I can update or
get the text property?
Thanks
Alex
"Teemu Keiski" <joteke@.aspalliance.com> wrote in message news:<elLAShQXEHA.4064@.TK2MSFTNGP11.phx.gbl>...
> Hi,
> here is an example how to loop through controls on the Page:
> http://www.aspnet101.com/aspnet101/tips.aspx?id=97
> If you want to access Text property, you need to have typed reference (cast
> it to TextBox with CType and set the value to the property).
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
> http://blogs.aspadvice.com/joteke
> "Alex Shirley" <postings@.alexshirley.com> wrote in message
> news:e9704b08.0406280400.238ba501@.posting.google.c om...
> > HI
> > I'm trying to iterate through all the textboxes on a webpage and trim
> > them for spaces.
> > i.e. If a user enters " hello world " we correct it to "hello
> > world"
> > So far I've come up with this:
> > -----------------------
> --
> > 'Trim all textboxes
> > Dim ThisControl As System.Web.UI.Control
> > For Each ThisControl In Me.Controls
> > If ThisControl.GetType().ToString() =
> > "system.Web.UI.WebControls.TextBox" Then
> > ThisControl.text = Trim(ThisControl.text)
> > 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> > stuck! Please help...
> > End If
> > Next ThisControl
> > -----------------------
> --
> > The problem I have is not really with the trim function. It's the fact
> > that I cannot update the control text value. It won't allow the .text
> > property at all in this example because "thiscontrol" is not actually
> > aware that the control assigned to it is actually a textbox. Is there a
> > way to tell it it's a textbox so I can access this property, or is there
> > another way around this?
> > Can you help?
> > Many Thanks!
> > Alex
Trim Each textbox control
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
----
--
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
----
--
Can you help?
Many Thanks!
Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.
"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.com...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> ----
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> ----
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Any answers folks?
Cheers
Alex
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Trim Each textbox control
I'm trying to iterate through all the textboxes on a webpage and trim
them for spaces.
i.e. If a user enters " hello world " we correct it to "hello
world"
So far I've come up with this:
------------------------
'Trim all textboxes
Dim ThisControl As System.Web.UI.Control
For Each ThisControl In Me.Controls
If ThisControl.GetType().ToString() =
"system.Web.UI.WebControls.TextBox" Then
ThisControl.text = Trim(ThisControl.text)
'Above line is wrong syntax, I want to trim the textbox here, but I'm
stuck! Please help...
End If
Next ThisControl
------------------------
Can you help?
Many Thanks!
Alexuse RTrim() and LTrim().
R for right and L for the left side to remove spaces.
"Alex Shirley" <postings@.alexshirley.com> schreef in bericht
news:e9704b08.0406240318.6e352a45@.posting.google.c om...
> HI
> I'm trying to iterate through all the textboxes on a webpage and trim
> them for spaces.
> i.e. If a user enters " hello world " we correct it to "hello
> world"
> So far I've come up with this:
> -----------------------
--
> 'Trim all textboxes
> Dim ThisControl As System.Web.UI.Control
> For Each ThisControl In Me.Controls
> If ThisControl.GetType().ToString() =
> "system.Web.UI.WebControls.TextBox" Then
> ThisControl.text = Trim(ThisControl.text)
> 'Above line is wrong syntax, I want to trim the textbox here, but I'm
> stuck! Please help...
> End If
> Next ThisControl
> -----------------------
--
> Can you help?
> Many Thanks!
> Alex
Hi Richard
The problem I have is not really with the trim function. It's the fact
that I cannot update the control text value. It won't allow the .text
property at all in this example because "thiscontrol" is not actually
aware that the control assigned to it is actually a textbox. Is there a
way to tell it it's a textbox so I can access this property, or is there
another way around this?
Any answers folks?
Cheers
Alex
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Trim function in VB.NET
In my code the value of strWebService is initially "2 " (that is the number two followed by a space). I then use trim to eliminate the space:
strWebService = readHtmlPage(strTMQuery)
strWebService = Trim(strWebService)
I then run strWebService through a SELECT statement and it always defaults to ELSE:
Select Case strWebService
Case "0"
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case "1"
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case "2"
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select
What am I doing wrong?
MikeHello -
Perhaps you might want to do a conversion to an integer for the case statement?
good luck
take care
tony
I added the following line before my select statement:
Dim intWebService As Integer = CInt(strWebService)
I then removed the double quotes from my case expressions and ran the code but still got the ELSE statement. VB doesn't require BREAK does it?
did you trying doing a response.Write(intWebService) right before the case statement so you can verify the value?
response.write("service =" & strWebService & ".")
Take note of the spaces and period. Should be
service =2.
My code now reads like this (I added the = signs to the label just to make sure the TRIM did its job...)
strWebService = readHtmlPage(strTMQuery)
strWebService = RTrim(strWebService)
Dim intWebService As Integer = CInt(strWebService)lblTest.Text = "=" & intWebService.ToString & "="
lblTest.Visible = TrueSelect Case strWebService
Case 0
pnlLogin.Visible = False
pnlPassengerList.Visible = True
Case 1
lblLoginError.Text = "Password is wrong...<br /><br />"
lblLoginError.Visible = True
Case 2
lblLoginError.Text = "E-mail address incorrect or not a valid user...<br /><br />"
lblLoginError.Visible = True
Case Else
lblLoginError.Text = "Unknown Error: " & strWebService & "<br /><br />"
lblLoginError.Visible = True
End Select
I still get the ELSE... Plus, my label does infact read 2... I don't get what I could be doing wrong...
Your select Statement is still referring to strWebService... Change it to intWebService...
Ha ha, good call. It works. Thanks guys. Strings in SELECT CASE statements SUCK!
trim function
thanks
Regards
GohIs it a boolean or some string variable declared elsewhere in your code?
Apparently this isn't an ASP.NET question, the 'original' post is here:
http://www.vbforums.com/showthread.php?p=2067378#post2067378