Saturday, March 31, 2012

Triggering event, listbox

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

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

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 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?

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

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

I have two tables (STOCK_ITEM and SEASONAL):

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

I have two tables (STOCK_ITEM and SEASONAL):
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',' 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

trim

How do I trim a value that has whitespace after the last character?
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

I have this code and it works great for some of the numbers but not ther other.

<%# 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

How to remove null objects from an array? When I use the split function, I end up having an empty first element. How do I remove this? Any code is welcome...
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?

I have the following in a dataset --Yeild - 15 Points - (3/6) And to do a calculation I need to pull the 3 position out of the ( ) section. It also has a capability of being something like the following --Yeild - 15 Points - (10/12) instead. Any ideas on how I would go about this?
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

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 ?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

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 ?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

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!

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

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!
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

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!

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

Hey,

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 = True

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

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

does anyone knows what does Trim(!Delete & "") means? what is this Delete ?
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

Trim fields in Text File

Hi

I have a text file with 116 fields separated by commas. How would I open the text file and trim all white spaces from each field and then close file?

Thanks

You can Use String.Split function to get array of all string with whitespace than trim that string and Use String.Join function to get comma seperated string

than store it in file


Even simpler would be to run a regex replace on your textfile after readingit.

Regex.Replace(strInput, "\s+", " ")

Trim Each textbox control - Repost

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!
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.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
> ----
--
> 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@.TK2MSFTNGP1
1.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 (cas
t
> 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.com...
> --
> --

trim left 5 character.

Hi guys

I am using vb.net

I have this "12.95-ups ground" string and I need to get the string after the dash

could you send me your suggestions please.

thanks

Cemal

Hi, try this:

Dim myStrAs String ="12.95-ups ground"Dim myTrimAs String = Mid(myStr, InStr(myStr,"-") + 1)

try something like below

index=yourStringVariable.IndexOf(".");
then
YourString.Substring( check what parameter this function requires)


string _strTest = "12.95-ups ground";
Response.Write ( _strTest.Substring ( 6 ) ) ;

Thanks

-Mark post(s) as "Answer" that helped you


dim str as string

str="12.95-ups ground"

dim newVal as string

newVal=str.substring(str.indexof("-")+1)

response.write(newVal)

trim large text

Hi! I have a function that trim large text, but the problem is that it cuts off the last word, so it's not making sense. Is there a function that trim large text in a nice way, making sure the last word is preserved. Thanks for any tip!

Can you just use Trim(myString) ?


You could also use Regular expressions :

using System.Text.RegularExpressions;

private string RemoveSpaces(string str)
{
string result = "";
Regex regulEx = new Regex(@."[\s]+");
result = regulEx.Replace(str," ");
return result;
}

Original code :Laxshmi

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--



I probably didn't explain what I am doing. If I have a large text to pull from the database and I 'd like just a small portion to be displayed in gridview cell, I am uisng:

Substring(0,Math.Min(100, Eval("Bulletin").ToString().Length)) but this cuts off any last words.


Thank you for the reply! I am looking to shorten text (pulled out of the database)for display in gridview.

Cheers!


:)

Here you go. Even though this is asp code, you will get the idea

http://www.codeproject.com/asp/textpreview.asp

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--


James,

if I understand you right then you're saying that you want the last word within the 100 character max limit to be preserved and to not be chopped in two, right? Here's a bit of code that might accomplish it for you if that is what you're looking for. It just involves string manipulations is all.

string myStr ="This string should be cut off at the 25th character, and preserve the final word.";string myStr25 = myStr.Substring(0, 25);int lastIdx = myStr25.LastIndexOf(" ");string finalStr = myStr25.Substring(0, lastIdx);

Let me know if you need help from there, but you should be able to adapt it to your need.


If you don't want to cut off words, just trim to the last index of a space.

string text = Eval("Bulletin").ToString();

if (text.Length > 100)

{

text = text.Substring(0, 100);

text = text.Substring(0, text.LastIndexOf(' ') + 1);

}


or how about trying this :

<ItemTemplate>
<%# Eval("Bulletin").ToString().Substring(0, 20) + "..." %>
</ItemTemplate>

Just make sure that all the strings are above 20 characters.

Edit : This code would probably cut off the last words. I do not have my visual studio with me, but what you can do is use this code with the suggestion posted by other members to get your solution.

HTH,
Suprotim Agarwal

--
http://www.dotnetcurry.com
--


I did this but it gave me 95 instead of my text:

<%# Eval("Bulletin").ToString().Substring(0,100).LastIndexOf(" ")%>

I am doing it in the aspx, makes it harder for me.


This is my datalist:

<asp:DataListID="dlBulletins"runat="server">

<ItemTemplate>

<strong><%# Eval("DisplayName")%></strong>

<br/>

<%#formatDate((DateTime)Eval("Bulletin_Date"))%><br/>

<%# Eval("Bulletin").ToString().Substring(0,Math.Min(100, Eval("Bulletin").ToString().Length)) %>

</ItemTemplate>

How can I use the string text in datalist template?

Cheers!

<separatorTemplate><hrnoshade="noshade"size="1"/>

</separatorTemplate>

</asp:DataList></p>


I am using this but it's only returning the first letter!!

<%# Eval("Bulletin").ToString().Substring(0,100).Substring(0,Eval("Bulletin").ToString().LastIndexOf(' ')) %>


It sounds like it's impossible to do this in the datalist!


Thanks friend!! I don't know what i was thinking, I made a function in the code behind called trimtext, then used it in the aspx. Work great now!

Cheers!

Trim String

Hi

I want to trim the end of a string placed on my page.

I want to make it so that even if the text is 100 char long it will only display the first 15 characters.

Is this correct, i cant seem to make it work.

Regards
Ant

<%#Container.DataItem("OutboundCarrierName").ToString.Trim("15") %>

use Substring function in place of this:

<%#Container.DataItem("OutboundCarrierName").ToString().Substring(0,15) %>

thanks


Perfect, that works.

trim querystring

Is there a way to request the whole querystring after the "?"

I want to pull every name value pair out of the querystring in one string.

Thanks!

mike123You may try "Request.QueryString".
No luck

Anything else ?

Thanks!
mike123
I think Request.ServerVariables("QUERY_STRING") will return what you are after?

Simon

Trim TextBox spaces

I am facing difficulity of having to Trim Spaces in Textbox.I am given a task of needing to trim spaces in the textbox and not to allow space at the front and at the back of the textbox as when u enter a space in front of the textbox it will be a totally different data from the one which has no space. So can anyone help me about the trim in Asp.net 2.0 c# languague.

<trclass="i4">

<tdclass="i5">

<span><span><spanclass="i6">C</span>USTCODE</span><spanclass="i6">

</span>

</span>

</td>

<tdclass="i7">

<asp:RequiredFieldValidatorID="RequiredFieldValidator2"runat="server"ControlToValidate="CUSTCODETextBox"

ErrorMessage="*"Font-Bold="False"></asp:RequiredFieldValidator></td>

<tdcolspan="2"class="i8">

<asp:TextBoxID="CUSTCODETextBox"runat="server"Text='<%# Bind("CUSTCODE") %>'MaxLength="20"></asp:TextBox></td>

<tdrowspan="10"class="i9"></td>

When you are saving the data in your code behind, you can trim the text using this code:

string customerCode = CUSTOMCODETextBox.Text.Trim();

That will get you the value entered by the user, without any leading or trailing spaces.

Trim string to fit in fixed width Table Cell [Edited by Adec, moderator]

I have the following BIG problemSmile [:)]
The column of datagrid is bind to a database field.
If lenght of string is bigger than the column width i want to trim the string.
No metter if the trimmed word has sense.
I would like to know if anyone knows if there is a way to calculate
string width in pixel in connection to font size used in that particular cell.
You can check the string size and do what you need to with it in your DataGridItemCreated event handler.
that's ok for the position where check, but the problem is how measure the width in pixel of the string:-)
Your getting confused, and making this to complicated. You dont measure strings in pixels, you measure strings in Charatchers, figure out how many charatchers will fit in the column of your datagrid, and trim the string to that amount of chars, I would recomend trimming it to 3 less chars than will fit and appending on a ... so that users know it's been trimmed.
Remember, capital letters take up more space than lower case ones, and different ascii chars can take up a space and a half in some cases purley literally speaking, like the @. symbol.

I would suggest you use sql to get the substring - select substring(myfield, 1, 10) as myfield from my table. This gets the first 10 characters. To add the "..." then select substring(myfield, 1, 7)+'...' as myfield from my table


It is ok, i will follow your indication. But still look for a method like TextWidth("...") to use in application.
Thanks. Best Regards

Trim trailing 0 from decimal place of number

Hi,

I am having difficulty trimming any traling 0's from my decimal numbers.
I store then in the database to 2 decimal places.
This means that when they come back to my application they still diply with
all the decimal places

eg

10.00 displays as 10.00
10.10 displays as 10.10

what I would like to achieve is the following

10.00 displays as 10
10.10 displays as 10.1

many thanks in advance

cheers

martin.string.Format("{0}",10);
string.Format("{0}",10.10);

should do the trick. Actually the above behavior should be the default
behavior...

+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
-----------
Making waves on the Web

"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message
news:OXKXwadbEHA.2216@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am having difficulty trimming any traling 0's from my decimal numbers.
> I store then in the database to 2 decimal places.
> This means that when they come back to my application they still diply
with
> all the decimal places
> eg
> 10.00 displays as 10.00
> 10.10 displays as 10.10
> what I would like to achieve is the following
> 10.00 displays as 10
> 10.10 displays as 10.1
> many thanks in advance
> cheers
> martin.

Trim trailing 0 from decimal place of number

Hi,
I am having difficulty trimming any traling 0's from my decimal numbers.
I store then in the database to 2 decimal places.
This means that when they come back to my application they still diply with
all the decimal places
eg
10.00 displays as 10.00
10.10 displays as 10.10
what I would like to achieve is the following
10.00 displays as 10
10.10 displays as 10.1
many thanks in advance
cheers
martin.string.Format("{0}",10);
string.Format("{0}",10.10);
should do the trick. Actually the above behavior should be the default
behavior...
+++ Rick --
Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
--
Making waves on the Web
"martin" <Stuart_REMOVE_36@.yahoo.com> wrote in message
news:OXKXwadbEHA.2216@.TK2MSFTNGP10.phx.gbl...
> Hi,
> I am having difficulty trimming any traling 0's from my decimal numbers.
> I store then in the database to 2 decimal places.
> This means that when they come back to my application they still diply
with
> all the decimal places
> eg
> 10.00 displays as 10.00
> 10.10 displays as 10.10
> what I would like to achieve is the following
> 10.00 displays as 10
> 10.10 displays as 10.1
> many thanks in advance
> cheers
> martin.
>

Trim to a specific alphanumeric quotable

HI all,

I am using c# and I am trying to use the windows authentication to recognize the users.
(User.Identity.Name)

Unfortunately, the users will belong to different domains and there fore their identity will look different. i.e. domain\username or net\username.

How can I remove everything before the username including the backslash?

thank you in advance,

GorginioHave you looked into substring??

// psuedo code

userName = User.Identity.Name.SubString(User.Identity.Name.IndexOf("\"));

That may or may not work.
Welcome to the ASP.NET forums, Gorginio.

You can use the following code:

 // get the username ... but I'll fake it here
string fullUsername = @."domain\username";

// trim away any domain that may form part of the username
string trimmedUsername;
int indexOfSlash = fullUsername.IndexOf( @."\" );
if (indexOfSlash > -1)
{
trimmedUsername = fullUsername.Substring( indexOfSlash + 1, fullUsername.Length - indexOfSlash - 1 );
}
else
{
trimmedUsername = fullUsername;
}

I hope this helps.

Trim the first character

How do i trim the first character.
I have string $22.22 and i want to be left with 22.22
I cant use subString(int,int) because i dont know the length of the stringYou can determine the length using the .Length property. So you can trim in C# like this:
string s = "$22.22";
s = s.Substring(1, s.Length - 1);
's' will now be "22.22"
There is also an overloaded substring method that only requires the starting character position:

strimmed=s.substring(1)

Trim URL String

I am trying to populate selected values from a drop-down list into URL params. I have the below code, which is supposed to remove the trailing comma from the end of the URL, but it does not seem to be working. Does anyone see anything obviously incorrect?

Thanks in advance.
----------

if (lbxWFTemplate.Visible ==true)

{

strURL +="WFTemplate=";

foreach (ListItem liWFTemplatein lbxWFTemplate.Items)

{

if (liWFTemplate.Selected)

{

strURL += liWFTemplate.Value.ToString() +",";

}

}

strURL.TrimEnd(",".ToCharArray());

I actually figured this out right after I posted. Trimend() returns a string, so the following was changed, and the code works as expected now:
strURL = strURL.TrimEnd(",".ToCharArray());

Trim URL

Hi,
I am involved in designing a website in which on a certain page(that contains a form) if some message is to be shown to the user the URL looks like
http://myserver/somepage.aspx?message=.....
Now if on that page the user requests re-submits the form I want the URL to be trimmed as simply http://myserver/somepage.aspx

Also is there some way that I can send such error messages through some means(like POST) such that there is no change in the url.If yes plz elaborate on it

Cheers,
-Aayush

Why don't you pass the parameter into a session, so instead of passing ?message=.....

do

Session["message"] = "...";

and in the next page you do:

string message = Session["message"].ToString();

Session.Remove("message");


you can use server variables and retrieve the required info

Trim Trailing Comma in an Array

Hi - I thought this would be easy but I can't find an answer. I have an ArrayList seperated by commas and I want to trim off the last comma in the list. The VB function throws an error. Thanks

Dim myList As New ArrayList

'Does not work
myList.Trim()

Hi,

You need to explain your problem a little better.

Do you have an arraylist of strings and you want to trim off the last comma of each string in the arraylist ?

Roy.


I'm not sure if I understand what you are trying to do. How do you have an ArrayList seperated by commas? The point of an Array is that each item is accessible through an index, and it doesn't need a delimeter. If you want to remove an item from the array, you can use myList.Remove(object to remove) or myList.RemoveAt(index to remove). The Trim method is for strings.

Hi - I'm populating an arraylist from a datareader like below

Dim myList As New ArrayList
Dim dr As SqlDataReader
Dim count As Integer

strSQLConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnString"))
strSqlText = "getIndustries"
cmd = New SqlCommand(strSqlText, strSQLConn)
cmd.CommandType = CommandType.StoredProcedure

Try
strSQLConn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
With dr
If .HasRows Then
While .Read
myList.Add(.GetString(0))
myList.Add(",")
count += 1
End While
End If
End With

End result below. I need to remove that last comma at the end of Video Rentals.

Travel Services,Trucking & Shipping,Utilities Electric,Utilities Natural Gas,Utilities Water & Waste,Video Rentals,


Ok the easy answer is to use:

myList.RemoveAt(myList.Count - 1);

However I have to ask, why are you inserting commas after each value? And why are you using an arraylist? It seems to me that a string array would be more efficient. Also, what's the purpose of the "count" integer? You can use myList.Count to see how many objects are in the ArrayList (assuming you aren't inserting commas in between).


To take off the last comma in the last element of the Array, you could use something like

myList.Item(myList.Count - 1) = myList.Item(myList.Count - 1).ToString.Trim(",")

Depending on what you are doing with the array later, it may work better to leave the commas out of the array and just add them when you display the contents of the Array.

Otherwise, you could just build a string instread of an array.

Something like this:

Dim myList As New StringBuilder()While .Read myList.Append(.GetString(0)) myList.Append(",") count += 1End While

Heck, now that I think of it, you could be using a StringBuilder too, which is *much* more efficient with a large number of concatenations:
Dim myListAs New ArrayListDim drAs SqlDataReaderDim countAs Integer Dim mySBAs New StringBuilder() strSQLConn =New SqlConnection(ConfigurationSettings.AppSettings("ConnString")) strSqlText ="getIndustries" cmd =New SqlCommand(strSqlText, strSQLConn) cmd.CommandType = CommandType.StoredProcedureTry strSQLConn.Open() dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)With drIf dr.HasRowsThen While dr.Read mySB.Append(dr.GetString(0) + ",") count += 1End While End If End With

Then you could do something like this to trim it:

String myResult = mySB.ToString().TrimEnd(",".ToCharArray());
HTH

If your array is a string like

Dim sTest = "A,B,C,D,"

Then a test along the lines of

If sTest.EndsWith(",") Then sText = sTest.Substring(0, sText.Length - 1)

should do it.

(I am awaiting my copy of VS2005 as part of my MSDN subscription, so the above is unchecked as to syntax.)



hello ,

here is a little idea i dont know if this function is available in vb.net since i m a c# programmer

may be it help you ,

mylist.RemoveAt(mylist.LastIndexOf(

","));

Regards

Gurpreet


Thanks very much!

Trim whitespace (start and end) of string

Just wondering how you can trim the whitespace of a string for the start and end of it.


e.g. " My String "

Thanks!

nothing more then string.trim(); put the string value in a string variable.

greets,

Erdem


Here are the methods available to you

publicstring Trim(paramschar[] trimChars);

publicstring Trim();

publicstring TrimStart(paramschar[] trimChars);

publicstring TrimEnd(paramschar[] trimChars);


Hi,

try this

String myString = " My String ";

myString.Trim(' ');

Regards

TrimEnd of strings help needed!

Ok, I'm a flash developer, comfortable with actionscripting... so keep this in mind and thanks for any help.

I got some code from a german site that pulled the ID tags from a directory of mp3s. This is for a client who wants to populate a flash mp3 player with his own music. Anyways, I got the flash part, which will pull the data from an XML file. What I want is for the client to populate the ID tags of the mp3s, the .NET page reads that and creates an xml file out of it. So here's the code:


<%@dotnet.itags.org. Page Language="C#" Debug="True" EnableViewStateMac="false" %>
<%@dotnet.itags.org. Import Namespace="System" %>
<%@dotnet.itags.org. Import Namespace="System.IO" %>
<%@dotnet.itags.org. Import Namespace="System.Text.RegularExpressions" %
<script language="C#" runat="server"
private static String ConvertByteToString(byte[] bytes, int pos1, int pos2)
{
//pos2 muß größer oder gleich pos1 sein und
//pos2 darf Länge des Arrays nicht überschreiten
if ((pos1 > pos2) || (pos2 > bytes.Length - 1))
{
throw new ArgumentException("Aruments out of range");
}

//Länge des zu betrachtenden Ausschnittes
int length = pos2 - pos1 + 1;

//neues Char-Array anlegen der Länge length
Char[] chars = new Char[length];

//packe alle Bytes von pos1 bis pos2 als
//Char konvertiert in Array chars
int started = 0;
for (int i = 0; i < length; i++)
{
chars[i] = Convert.ToChar(bytes[i + pos1]);

}//end for

//konvertiere Char-Array in String und gebe es zurück
return new String(chars);
}

void Page_Load(object s, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:/mp3directory");
FileInfo[] rgFiles = di.GetFiles("*.mp3");
String xmlcontent = "<?xml version='1.0' standalone='yes'?><songs>";
foreach(FileInfo fi in rgFiles)
{

//mp3 parser section
Stream s1 = fi.OpenRead();

byte[] bytes = new byte[128];
s1.Seek(-128, SeekOrigin.End);
int numBytesToRead = 128;
int numBytesRead = 0;
while (numBytesToRead > 0) {
int n = s1.Read(bytes, numBytesRead, numBytesToRead);

if (n==0) {
break;
}
numBytesRead += n;
numBytesToRead -= n;
}
s1.Close();

String tag = ConvertByteToString(bytes, 0, 2);
//if (tag != "TAG") {
//return false;
//}

String m_title = ConvertByteToString(bytes, 3, 32);
m_title = m_title.TrimEnd();
String m_artist = ConvertByteToString(bytes, 33, 62);
String m_comment = ConvertByteToString(bytes, 97, 126);
//m_album = ConvertByteToString(bytes, 63, 92);
//m_year = Int32.Parse(ConvertByteToString(bytes, 93, 96));

//m_genre = bytes[127];

//end mp3 parser section

xmlcontent = xmlcontent + "<song title='"+m_title+"' artist='"+m_artist+"' path='" + fi.Name + "' />";
}
xmlcontent = xmlcontent + "</songs>";
//xmlcontent = Regex.Replace(xmlcontent, " ", "*");
FileInfo t = new FileInfo("C:/mydirectory/songInfo.xml");
StreamWriter Tex =t.CreateText();
Tex.WriteLine(xmlcontent);
Tex.Close();
Response.Write("Radio Listings created.");
Response.Write(xmlcontent);
}

</script>

Problem is, the silly thing is creating a string with what looks like TONS of extra spaces at the end. What I guess it's doing is creating a string 32-3 characters long for the title (as an example). I tried using TrimEnd, but that didn't work. I even tried just as a test to replace all the spaces with asterisks (you can see it commented above), but even that didn't work.

It looks something like this: <song title='Hey Ya! ' artist='Outkast ' path='HeyYa.mp3' /
Very frustrating.

Thanks!Not exactly sure I was clear about what the problem is. If you look above at the xml that gets generated, you'll notice after the title there is a space. In the xml file that is created, there are a ton of spaces, but my pasting in the example strips out the spaces.

Anyways, I _think_ I figured it out. I removed the Streamwriter part and replaced it with XmlTextWriter. This changed the spaces to "�", and flash just ignores that. Everything works exactly as it should. I'm assuming I have a encoding issue with transferring bytes to strings and then to xml. Eh... it works, so who cares I suppose.

<%@. Page Language="C#" Debug="True" EnableViewStateMac="false" %>
<%@. Import Namespace="System" %>
<%@. Import Namespace="System.IO" %>
<%@. Import Namespace="System.Xml" %>
<%@. Import Namespace="System.Text" %
<script language="C#" runat="server"
private static String ConvertByteToString(byte[] bytes, int pos1, int pos2)
{
//pos2 muß größer oder gleich pos1 sein und
//pos2 darf Länge des Arrays nicht überschreiten
if ((pos1 > pos2) || (pos2 > bytes.Length - 1))
{
throw new ArgumentException("Aruments out of range");
}

//Länge des zu betrachtenden Ausschnittes
int length = pos2 - pos1 + 1;

//neues Char-Array anlegen der Länge length
Char[] chars = new Char[length];

//packe alle Bytes von pos1 bis pos2 als
//Char konvertiert in Array chars
int started = 0;
for (int i = 0; i < length; i++)
{
chars[i] = Convert.ToChar(bytes[i + pos1]);

}//end for

//konvertiere Char-Array in String und gebe es zurück
return new String(chars);
}

void Page_Load(object s, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo("C:/mp3directory");
FileInfo[] rgFiles = di.GetFiles("*.mp3");
XmlTextWriter writer = new XmlTextWriter("C:/xmldirectory/songInfo.xml", Encoding.UTF8);

// start writing!
writer.WriteStartDocument();
writer.WriteStartElement("songs");

foreach(FileInfo fi in rgFiles)
{

//mp3 parser section
Stream s1 = fi.OpenRead();

byte[] bytes = new byte[128];
s1.Seek(-128, SeekOrigin.End);
int numBytesToRead = 128;
int numBytesRead = 0;
while (numBytesToRead > 0) {
int n = s1.Read(bytes, numBytesRead, numBytesToRead);

if (n==0) {
break;
}
numBytesRead += n;
numBytesToRead -= n;
}
s1.Close();

String tag = ConvertByteToString(bytes, 0, 2);
//if (tag != "TAG") {
//return false;
//}

String m_title = ConvertByteToString(bytes, 3, 32);
String m_artist = ConvertByteToString(bytes, 33, 62);
String m_comment = ConvertByteToString(bytes, 97, 126);
//m_album = ConvertByteToString(bytes, 63, 92);
//m_year = Int32.Parse(ConvertByteToString(bytes, 93, 96));

//m_genre = bytes[127];

//end mp3 parser section

writer.WriteStartElement("song");
writer.WriteAttributeString("title", m_title);
writer.WriteAttributeString("artist", m_artist);
writer.WriteAttributeString("path", fi.Name);
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndDocument();
writer.ToString();
writer.Close();
Response.Write("Radio Listings created.");

}

</script

Trimming

I am trying to trim a session variable to get the last three characters.Here is the code:

Dim CancelTrim()AsChar = {"","cc9"}

If Session("confirm").trimend(CancelTrim) ="ca1"Then

Label1.Text ="it was cancelled"

EndIf

It's not working though, go figure. So, how would I get these to trim off the last three characters so I can do what I need to do?

Thanks

Hello,

so what does it return from ther TrimEnd call? TrimEnd trims from the end of the string, so isn't that from the wrong direction if you want the last three characters? So maybe TrimStart would work better?

On the other hand, couldn't you write something like:

Dim ConfirmStringAs String = Cstr(Session("confirm"))Dim LastThreeCharsAs String = ConfirmString.Substring(ConfirmString.Length - 3)If LastThreeChars ="ca1"Then'CheckEnd If

Triming the Back Button

Is there a way to remove items from the Back Button programatically? When a
user gets to a certain page and presses the back button I want to bypass
some of the pages that he got to on the way to that page. For example, I
don't want the user to see the forms he posted before he got to this page.
To illustrate, suppose the users sees these pages in sequence:
P1-->P2-->P3-->P4
What I want is when the user is viewing P4 and presses the back button he
goes to P1 rather than P3.Hi,
as far as I know the only way to achieve this behavior is only by
supplying your own navigation mechanism. I'll be happy to hear other
options...
Natty Gur[MVP]
blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.
>
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.
Did I just send a blank response? Sorry if so.
There's no good way to do this. What if the user is viewing P4 and enters P3
into the browser's address bar? What if the user creates a new browser
window and has that window go to P2 while the first one goes back to P3?
This is one of the characteristics of a web application. Because you didn't
create the program the user is using (the browser), you don't have complete
control over what the user does with that program. The trick is to simply
get over it and come up with another way of accomplishing what you need.
--
John Saunders
johnwsaundersiii at hotmail

Triming the Back Button

Is there a way to remove items from the Back Button programatically? When a
user gets to a certain page and presses the back button I want to bypass
some of the pages that he got to on the way to that page. For example, I
don't want the user to see the forms he posted before he got to this page.

To illustrate, suppose the users sees these pages in sequence:

P1-->P2-->P3-->P4

What I want is when the user is viewing P4 and presses the back button he
goes to P1 rather than P3.Hi,

as far as I know the only way to achieve this behavior is only by
supplying your own navigation mechanism. I'll be happy to hear other
options...

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.
"Ron Lautmann" <ronUNDERSCORElautmann@.pacbell.net> wrote in message
news:eARi7G3TEHA.972@.TK2MSFTNGP10.phx.gbl...
> Is there a way to remove items from the Back Button programatically? When
a
> user gets to a certain page and presses the back button I want to bypass
> some of the pages that he got to on the way to that page. For example, I
> don't want the user to see the forms he posted before he got to this page.
> To illustrate, suppose the users sees these pages in sequence:
> P1-->P2-->P3-->P4
> What I want is when the user is viewing P4 and presses the back button he
> goes to P1 rather than P3.

Did I just send a blank response? Sorry if so.

There's no good way to do this. What if the user is viewing P4 and enters P3
into the browser's address bar? What if the user creates a new browser
window and has that window go to P2 while the first one goes back to P3?

This is one of the characteristics of a web application. Because you didn't
create the program the user is using (the browser), you don't have complete
control over what the user does with that program. The trick is to simply
get over it and come up with another way of accomplishing what you need.
--
John Saunders
johnwsaundersiii at hotmail

Trimming Blank Spaces in String

You can use the VB.NET function RTRIM.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net

"Temp" <tempmail@dotnet.itags.org.temp.com> wrote in message
news:bh1eg5$o2h@dotnet.itags.org.library2.airnews.net...
> I am trying to remove the blank spaces at the end of a string with the
> .Trim() function. Unfortunately, this removes ALL spaces, not just the
ones
> at the end. I need to preserve the spacing inside the string.
> Does anyone know how I can do this?
> Thanks,
> Ron
> --
> _____________________________
> Ron Rodenberg
> Lead Software Engineer
> Razorvision Technology, Inc.
> (214) 207-1688Do you know of a C# equivalent?

--
_____________________________
Ron Rodenberg
Lead Software Engineer
Razorvision Technology, Inc.
(214) 207-1688
"Steve C. Orr, MCSD" <Steve@.Orr.net> wrote in message
news:%23Qab%23wgXDHA.2392@.TK2MSFTNGP10.phx.gbl...
> You can use the VB.NET function RTRIM.
> --
> I hope this helps,
> Steve C. Orr, MCSD
> http://Steve.Orr.net
>
> "Temp" <tempmail@.temp.com> wrote in message
> news:bh1eg5$o2h@.library2.airnews.net...
> > I am trying to remove the blank spaces at the end of a string with the
> > .Trim() function. Unfortunately, this removes ALL spaces, not just the
> ones
> > at the end. I need to preserve the spacing inside the string.
> > Does anyone know how I can do this?
> > Thanks,
> > Ron
> > --
> > _____________________________
> > Ron Rodenberg
> > Lead Software Engineer
> > Razorvision Technology, Inc.
> > (214) 207-1688

Trimming a string to remove special & non-numeric characters

the string format is "XXXXXX-06-X-1234". how can i trim it so that it removes all the dashes and non-numeric characters? the result after such a trim would be "061234"

thanks in advance.

Create a function that removes any characters you don't want. In this case, it's pretty easy:

Function ParseDigits(ByVal strRawValue asString)As String Dim strDigitsAs String =""If strRawValue =Nothing Then Return strDigitsFor Each cAs Char In strRawValue.ToCharArray()If c.IsDigitThen strDigits &= cEnd If Next c' return the number string, or "" if no numbers were in the string.Return strDigitsEnd Function

You can always iterate through each character and build a new string (Use the StringBuilder class). You could also try using RegEx.Replace method to replace all non-numeric characters with an empty string. I don't know which method would perform faster, if I had to guess, I'd say the manual iteration approach.

Does anyone know an easier way to do this?


quickest way to do this (and best performance is with a Regex:

C#:

string initialString ="XXXXXX-06-X-1234";System.Text.RegularExpressions.Regex nonNumericCharacters =new System.Text.RegularExpressions.Regex(@."\D");string numericOnlyString = nonNumericCharacters.Replace(initialString, String.Empty);

VB:

Dim initialString asString ="XXXXXX-06-X-1234"Dim nonNumericCharactersAs New System.Text.RegularExpressions.Regex(@."\D")Dim numericOnlyStringAs String = nonNumericCharacters.Replace(initialString,String.Empty)

Enjoy.


I think you did that backwards. You're having him match all numbers and replace them with an empty string. He WANTS numbers!

C#:

string initialString ="XXXXXX-06-X-1234";System.Text.RegularExpressions.Regex nonNumericCharacters =new System.Text.RegularExpressions.Regex(@."[^0-9]");string numericOnlyString = nonNumericCharacters.Replace(initialString, String.Empty);

VB:

Dim initialString asString ="XXXXXX-06-X-1234"Dim nonNumericCharactersAs New System.Text.RegularExpressions.Regex("[^0-9]")Dim numericOnlyStringAs String = nonNumericCharacters.Replace(initialString,String.Empty)

the "d" is capitalised:

/d = [0-9]

and

/D = [^0-9]

either way, you can use /D or [^0-9]


bipro/ds2goat

thanks for the help! that function works great. one more question though. sometimes the first set of characters (XXXXXX-) can have a number. is there anyway to totally ignore those first 6 characters, then trim the remaining characters using the function above?

example: "221300-06-D-1234" would come out as "061234"

thanks again for the help


bipro/ps2goat

thanks for the help! that function works great. one more question though. sometimes the first set of characters (XXXXXX-) can have a number. is there anyway to totally ignore those first 6 characters, then trim the remaining characters using the function above?

example: "221300-06-D-1234" would come out as "061234"

thanks again for the help


Is this a consistent thing? I.e., do all of the strings you are working with have those six characters you want to ignore? What kind of consistent pattern is there in the data?

yes, it is a consistent pattern (AAANNN-NN-A-NNNN), where "A" is alpha & "N" is numeric. i want to always ignore the first 6 characters, whether they be alpha or numeric.

thanks again.


You can get rid of the first 6 characters by

string _test = "AAANNN-NN-A-NNNN";
_test = _test.Replace(_test.Substring(0,6), string.Empty);

Now apply the above regular expression on the _test;

Thanks


works perfectly! here's my entire function:

Dim testAs String ="SPM300-06-D-1234"test = test.Replace(test.Substring(0, 6),String.Empty)Dim nonNumericCharactersAs New System.Text.RegularExpressions.Regex("\D")Dim numericOnlyStringAs String = nonNumericCharacters.Replace(test,String.Empty)Response.Write(numericOnlyString)
thanks again for all the help. i really appreciate it.
test = test.Replace(test.Substring(0, 6),String.Empty)
It seems to me that it makes more sense to do one operation than 2. e_screw told you to do

but it would read better if you did this instead:

test = test.Substring(6)
This will return all characters after index 6 (or the seventh character, since you don't need the first hypen either). Good programming is being lazy, and being lazy means writing less code to do what you want (less = more efficient). =)