|
Hi
I have a listbox in aspx page and has some list in it.
Now i am trying to get the list count of the listbox from javascript.
I am trying to get that by using the following code.
function count()
{
var x = document.getElementById(<%=listbox1.ClientID %>);
var cnt = x.options.length;
}
I am using a master page here.
But the value cnt is not having any value.
I tried by using like this also
var cnt = x.length;
but still it gave me the result as undefined.
Please help me to get the count.
Thanks in advance
Naina
|
|
|
|
|
This works properly.
alert(document.getElementById('<%=ListBox1.ClientID %>').options.length);
I Love T-SQL www.aktualiteti.com
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
I am using a GridView and one of the fields is a DateTime. The values in this field can be null. When I call gvwDetails.DataBind() I get this error:
"String was not recognized as a valid DateTime."
I just want it to display an empty string if its a null value. It doesn't seem that hard but I have tried searching google and read a bunch of MS pages on GridViews and DataBind. The closest I have come is setting the ConvertEmptyStringToNull property in my field to true but its not doing anything. My code for the template field is:
<asp:TemplateField HeaderText="Date Due"> <br />
<EditItemTemplate> <br />
<asp:TextBox ID="txtDateDue" runat="server" Text='<%# Bind("DATE_DUE") %>'></asp:TextBox> <br />
</EditItemTemplate> <br />
<FooterTemplate> <br />
<asp:TextBox ID="txtNewDateDue" runat="server" Width="100" ></asp:TextBox> <br />
</FooterTemplate> <br />
<ItemTemplate> <br />
<asp:Label ID="lblDateDue" runat="server" Text='<%# Eval("DATE_DUE") %>'></asp:Label> <br />
</ItemTemplate> <br />
<HeaderStyle HorizontalAlign="Left" /><br />
</asp:TemplateField>
Is this really simple and I'm not seeing it? I'm sure there's some way of handling null values that I must not be seeing. Thank you for any help.
|
|
|
|
|
Cast the date to varchar or char in Query then try.
if u r using MySql then cast the date like this.
select cast(Date_Format(Date_Due,'%d %M %Y') as char) as Date_Due from table_name
if u r using Ms SqlServer then do it like this
select CONVERT(varchar(20), Date_Due, 107) AS Date_Due from table_name
You can change the date format according to requirement.
|
|
|
|
|
That works, thank you very much.
Scratch that, I had made it a bound column and forgot to change it back. When I change it back to a template field it still doesn't work.
I have found some stuff that seems helpful (like this http://stackoverflow.com/questions/584570/why-does-my-repeater-keep-crashing-on-evalnull-values[^]) but still can't get this to work with my DateTime field.
One more edit: Okay I figured it out. I had some code in my RowDataBound event that was formatting the dates and I had to modify it in the case of an empty string.
Thank you again for the help.
modified on Friday, July 10, 2009 1:02 PM
|
|
|
|
|
Hello all,
Iam new to C# and .NET but leanrt a lot while iam in here. I ran in to a situation, I have created a shopping cart application and made successfully all the way to the order confirmation. Now the client wants to reset the "Order Num" to zero on a daily basis.
i.e "Order Number" once order is placed has to start at 0 from 12 AM and has to be set to 0 at 12 PM so that they have a count on how many items they are selling per day.
How this can be achieved any help will be appreciated. Thanks in advance.
|
|
|
|
|
There are 2 obvious ways I can think of....
1 - Store the order date in the database, that way the order numbers don't need to be reset, you can simply provide a screen to display the total number of orders for a given day.
2 - Store the order date and order number in the database against each order. Create a new table called something like currentordernumber, with 2 columns date and nextordernumber, each time you create a new order query this table to get the next order number and update the table to set the nextordernumber +1. If the current date is different to the date in the currentordernumber table update the date in the table and set the order number to 1.
Option 1 is by far the best option IMO.
|
|
|
|
|
Thank you DoctorMick for a quick solution.
If I go with Option 1, there is a small issue. I also have to show the "Order Number" to the user so that they can take that to the store with them[Carry Out].
Like 7/9/09 -- orders 1 to 100. Purchaser can go a tell the restaurant for their order number that day.
7/10/09 -- order 1 to 150.
|
|
|
|
|
Well, for that reason you can add another column to the table, lets say OrderNrOfDay.
Every time you insert the order in the table, check if the date today is same as that of the last order. If yes, the increment the OrderNrOfDay else set it to 1.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thank You Manas
That makes sense, let me try that should fix me.
|
|
|
|
|
That's again problematic. You should take extra care to make the increment atomic as multiple users will be using the web site simultaneously. Your client's idea of resetting the order numbers to 0 each day is plain stupid. In such case, how do you refer to a order? You may need order number and the day order placed.
The option 1 suggested in the other reply is good. I am not getting what is the issue you are facing with that approach?
|
|
|
|
|
I accomplished this task by creating another table which has OrderId,OrderNum, Date, OrderNrOfDay. OrderNum is the FK here to PK of orders table.
Then OrderNum from marchant warehouse is always saved in database and for clients sake generating daily order numbers starting from 1 to so on and for records we have OrderNum.
This solved the issue.
|
|
|
|
|
Hi,
Guys I have a peculiar problem here, I need to display data from two tables having no fields at all common and want to display them in one gridview on the click of a radio button .
If radiobuttton(1) is selected then data from table one will be displayed and if radiobuttton(2) is selected then data from table two will be displayed.
each of the table is having field name as:
table(1)
fname lname mname abid
table(2)
fname lname mname cdid
is there some advice you guys can help me?
thanks
|
|
|
|
|
this seems easy enough to me. Change the data source of the gridview on the event of the radio button being clicked
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi Chris,
The problem is that even if I change the data sources ,the gridview which I am using has only one name(name of the coloumn here) so how will the grid view show second table's data?
|
|
|
|
|
each of the table is having field name as:
table(1)
fname lname mname abid
table(2)
fname lname mname cdid
gridview
fname lname mname abid
Now as you can see the gridview has a field name abid and this field is databound that is it has to have the same name as that with the respective table, so by my limited knowledge this gridview will show only one table's data but I want to display data of two tables in one gridview.
Is there a way out from this problem?
|
|
|
|
|
you have to change in select Query Like this .
for table(1) use the following Query.
select fname,lname,mname,abid from table(1)
and for table(2) the select Query will be.
select fname,lname,mname,cdid as abid from table(2)
now u have the same column name for both tables.
and if u want to change the headerText text of the column with condition of radio buttons.
after data bound like this.
GridView1.DataBind();
if (RadioButtonList1.SelectedValue == "one")
{
GridView1.Columns[3].HeaderText = "abid";
}
else
{
GridView1.Columns[3].HeaderText = "cdid";
}
|
|
|
|
|
How to select and return more than one values using select stored procedure.
How to configure login control using wizard.
How to edit connection string at configuration file or how to change database name, server name, username nad password.
|
|
|
|
|
I think you need to read my article on how to use google. Or perhaps try asking detailed, intelligent questions. You've asked three very different things. In each case, I have to ask, where are you stuck ? Do you not have any books on ASP.NET ? Do you not have access to google ? Have you tried reading some articles on the site ?
What have you tried ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: I think you need to read my article on how to use google
I feel that people just post a question at CP and go for a coffee break.
And boy, they have the answer by the time they come back.
So, it like why should I take any pains when someone else can do it for them.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
It sure looks that way.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I would rather suggest to buy a beginners’ book and start reading.
The questions you have asked are very basic and it would be difficult for you to continue with the task.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi,
Mix Wheels wrote: How to select and return more than one values using select stored procedure.
ANS 1 : Ans1[^]
Mix Wheels wrote: How to configure login control using wizard.
ANS 2 : Ans2[^]
Mix Wheels wrote: How to edit connection string at configuration file or how to change database name, server name, username nad password.
ANS 3 : Ans3[^]
See and try using the same method from GOOGLE and then post questions when you have any errors or if you stuck anywhere.
Hope you got it....
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
Hi everybody,
I've written this code for publish reports on ReportServer.Everything is ok, but if I have SharedDataSource it says:
---------------------------
The dataset ‘NewDT’ refers to the shared data source ‘NewDT’, which is not published on the report server.
---------------------------
what's wrong?
Dim TmpEncoding As New System.Text.UTF8Encoding
Dim TmpReportDefinition() As Byte = TmpEncoding.GetBytes(PRdl)
Dim TmpWarnings() As Warning = TmpRsProxy.CreateReport(PReportName, PParentPath, True, TmpReportDefinition, Nothing)
Dim TmpDataSources As DataSource() = TmpRsProxy.GetItemDataSources(PParentPath & "/" & PReportName)
For Each TmpDataSource As DataSource In TmpDataSources
Dim dSource As New DataSource
Dim dDefinition As New DataSourceDefinition()
dSource.Item = dDefinition
dDefinition.Extension = "Sql"
dDefinition.ConnectString = "Data Source=" + ClsSetting.DbServerName + ";Initial Catalog=" + ClsSetting.DbName
dDefinition.ImpersonateUserSpecified = True
dDefinition.Prompt = Nothing
dDefinition.WindowsCredentials = True
dDefinition.CredentialRetrieval = CredentialRetrievalEnum.Integrated
dSource.Name = TmpDataSource.Name
Try
TmpRsProxy.CreateDataSource(dSource.Name, ClsSetting.DataSourceLocation, True, dDefinition, Nothing)
If TypeOf (TmpDataSource.Item) Is DataSourceReference Then
Dim DsReference As New DataSourceReference()
Dim ds As New DataSource
DsReference.Reference = ClsSetting.DataSourceLocation + "/" + dSource.Name
Dim DataSources() As DataSource = TmpRsProxy.GetItemDataSources(PParentPath & "/" & PReportName)
ds = DataSources(0)
ds.Item = CType(DsReference, DataSourceReference)
ds.Name = TmpDataSource.Name
TmpRsProxy.SetItemDataSources(PParentPath + "/" + PReportName, DataSources)
End If
Catch ex As System.Web.Services.Protocols.SoapException
Throw ex
End Try
Next
</pre>
<div class="ForumSig">Best wishes</div>
|
|
|
|
|
Hey,
here is one solution you may need the same.
Try it[^]
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|