|
This populated the listbox:
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
Dim dr As SqlDataReader
Dim cn As New SqlConnection
Dim cd As New SqlCommand
cn.ConnectionString = MRMFunctions.WebConfigConnString
cd.Connection = cn
cn.Open()
Dim strSelectSQL = "SELECT [TitleID], [Title] FROM tblTitles WHERE [Deleted] = 0;"
cd.CommandText = strSelectSQL
dr = cd.ExecuteReader
ListBox1.DataSource = dr
ListBox1.DataTextField = "Title"
ListBox1.DataValueField = "TitleID"
ListBox1.DataBind()
dr.Close()
cn.Close()
End Sub
But there are still some problems.
Protected Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles ListBox1.SelectedIndexChanged
strID = ListBox1.SelectedValue
strTitle = ListBox1.SelectedItem.Text
txtID.Text = strID
txtTitle.Text = strTitle
End Sub
On the line strID=ListBox1.SelectedValue the strID variable is empty. The line below it is give me the error message, "Object reference not set to an instance of an object." Why does it need to be set to an instance of an object?
Thank you,
Quecumber256
|
|
|
|
|
The SelectedItem property returns null (Nothing in VB) if there is no selected item. You have to check for this before trying to use it.
Quecumber256 wrote: Why does it need to be set to an instance of an object?
It has to be set to an instance of an object in order for you to access the properties of that object.
---
Year happy = new Year(2007);
|
|
|
|
|
Sorry, I wasn't paying attention. I think this is correct.
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
Dim dr As SqlDataReader
Dim cn As New SqlConnection
Dim cd As New SqlCommand
cn.ConnectionString = MRMFunctions.WebConfigConnString
cd.Connection = cn
Dim strSelectSQL = "SELECT [TitleID], [Title] FROM tblTitles WHERE [Deleted] = 0;"
cd.CommandText = strSelectSQL
ListBox1.DataTextField = "Title"
ListBox1.DataValueField = "TitleID"
cn.open
dr = cd.ExecuteReader
ListBox1.datasource = dr
ListBox1.databind
cn.Close()
End Sub
|
|
|
|
|
This works! I can populate the listbox and retrieve the ID numbers. It seems there is a generic class build just for this purpose.
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles Me.Load
Dim dr As SqlDataReader
Dim cn As New SqlConnection
Dim cd As New SqlCommand
cn.ConnectionString = MRMFunctions.WebConfigConnString
cd.Connection = cn
cn.Open()
Dim strSelectSQL = "SELECT [TitleID], [Title] FROM tblTitles WHERE [Deleted] = 0;"
cd.CommandText = strSelectSQL
dr = cd.ExecuteReader
While (dr.Read)
ListBox1.Items.Add(New ListItem(dr("Title"), dr("TitleId")))
End While
dr.Close()
cn.Close()
End Sub
Thanks for all the help guys.
Quecumber256
|
|
|
|
|
Quecumber256 wrote: It seems there is a generic class build just for this purpose.
No, not really. The ListItem class is always used for the items in list controls.
If you use the override of the Add method that takes a string, it creates a ListItem object for you. If you data bind the control, the DataBind method creates the ListItem objects for you.
-- modified at 16:21 Friday 19th January, 2007
---
Year happy = new Year(2007);
|
|
|
|
|
hi friends
how to create search option in asp.net (eg;google).
any code please send me
thanx
regards
Kavi
|
|
|
|
|
I answered almost the exact same question[^] yesterday, so I'm going to assume you're the same person posting under a different account.
The article I posted didn't seem to meet your needs, so you need to be more specific about what your requirements are.
Jon Sagara
I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So i had to leave the place as soon as possible.
--Mr.Prakash
Blog | Site | Articles
|
|
|
|
|
Hi,
I have the legacy asp code in which I will now have to plug in some ASP.Net server controls to make one text box AJAX enabled. So my question is can we have a ASP.Net control in the old asp page(.asp not .aspx)
My asp code looks something like this.
<input type="text" id="txtPOsQLU" name="txtPOsQLU" size="10" maxlength="25" />
To make this Text box AJAX enabled, I am writing code like this
Append("<asp:TextBox ID=\"TextBox1\" runat=\"server\"></asp:TextBox>");
<atlas:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server">
<atlas:AutoCompleteProperties Enabled="true"
MinimumPrefixLength="1"
TargetControlID="TextBox1"
ServicePath="~/Services/ProductService.asmx"
ServiceMethod="FindProducts" />
</atlas:AutoCompleteExtender>
SO can I use asp:XXX in my .asp page? Plus if I have the Atlas dll in my project can I also use atlas:XXX here..
Thanks in advance
|
|
|
|
|
No you can't use asp.net inside of classic asp.
|
|
|
|
|
|
hi friends
this is interview question plz clarify this
1)What Happens when we try to update data in a dataset in .NET while the record is already deleted in SQLSERVER as Backend?
2)you have defined one page_load event in aspx page and same page_load event in code behind how will program run?
3)how do you make your site SSL Enabled?
regards
saravanan
|
|
|
|
|
I have been programming asp.net for 5 years, here is how I would answer.
1.If you are updating a record that has been deleted, then you haven't coded any record locking which is not good. I make database updates by calling stored procedures directly, I don't use the dataset. So if my stored proc didn't check if the record exists then it would execute but zero rows would be affected.
2. I've never tried that before because I don't put code in my aspx pages. However, it would only take a second to try it and see.
3. You have to set up a certificate in IIS. But you could just follow the instructions at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/secnetht16.asp
Just an aside, those are some terrible questions. 1. is bad because updating a dataset is terribly inefficient and should rarely be used. 2. Putting code in the ASPX page is not only pointless, it defeats the entire point of having a code behind page. 3. Most companies do not ask the developer to be responsible for configuring IIS. Setting up SSl is usually not the job of the developer. Not to mention that none of these questions gauge your intellect or ability. You have either come across those specific situations or your haven't. I would ask yourself if you really want to work at a company that asks such silly questions.
|
|
|
|
|
ToddHileHoffer wrote: 1. is bad because updating a dataset is terribly inefficient and should rarely be used.
I agree 100%, but my boss doesn't
|
|
|
|
|
I am is a new user of ASP.net, I create a web-page and I would like to know whenever a event happen when the client hits some thing in my page (ie: he/she mouse-click on any place in the web-page)
Can someone know how to do it? Thanks for any help
|
|
|
|
|
You would have to write custom javascript to handle the mouse click event and do a postback to the server. That makes no sense though. If you need to whenever the mouse is clicked you need to write a windows application, not a web app.
|
|
|
|
|
Thanks for the advice, I will try it!
|
|
|
|
|
Hi,
My Custom Validator DOESNOT want to execute Please help me.
Here's the code.. I am desperate..
Front-End
=========
<TD width="35%" colSpan="2">
<asp:TextBox id="txtUsername" tabIndex="18" runat="server" CssClass="smallFormBox" width="150" MaxLength="50"></asp:TextBox>
<asp:CustomValidator id="cstUsername" runat="server" ForeColor="#7C1E3F" Visible="False" ControlToValidate="txtUsername" OnServerValidate="CheckUsername" ErrorMessage="<Img border=0 width='10px' height='10px' src='../Images/Star.gif'>" tooltip="This username already exists" Enabled="True"></asp:CustomValidator>
</TD>
VB SCRIPT
=========
Protected Sub CheckUsername(ByVal sender As Object, ByVal e As ServerValidateEventArgs)
Dim ds As New DataSet
Dim objUser As New clsUser
objUser = New clsUser
ds = objUser.getUserNameDetails(Me.txtUsername.Text)
If (ds.Tables(0).Rows.Count > 0) Then
e.IsValid = False
End If
End Sub
|
|
|
|
|
I think the angle brackets in your error message may be confusing the parser... That's just an idea though.
|
|
|
|
|
Thanks for the reply.
I have found the problem after 1 week of debugging!!
You will never guess what is was...
...
...
I removed Visible="False" then it worked. I suppose visibility affects its functionality lol
|
|
|
|
|
Hi
guys can any one please let me know how to synchronize the information taken from ASp.NET calendar control with out look calendar control, please reply ASAP,thankx in advance for ur replies.
regards.
|
|
|
|
|
Hi Friends,
I have a very strange problem. In my asp.net form, I have one text box and two buttons. through javascript, I am setting focus on textbox. What I am seeing that cursor is blinking in the text box, and my first button also have focus. I want this focus should be on the second button but I am not able to do that. can somebody please help me on this. My code is as below:
<asp:textbox id="txt" runat="server">
<asp:button id="btn1" runat="server" text="Button1">
<asp:button id="btn2" runat="server" text="Button2">
document.getElementById('txt').focus();
Please help.
Thanks,
Amit
-- modified at 10:00 Friday 19th January, 2007
|
|
|
|
|
Edit the question and check the "Ignore HTML..." checkbox, so we can see it.
|
|
|
|
|
you can put the set focus snippet of code in the onload event...
<< >>
|
|
|
|
|
Dear friends,
I recently know about the Link-exchange. I make the Project of Link Exchange.
Just I want to know how we can send the mail automatically after some time duration to other, using Asp.net.
If anybody has the information about to send mail automatically through asp.net please help me by replying.
thank you.
Ravi Khimani
|
|
|
|
|
I want to know about the Hit-Counter. That is helpfull to user to know how many times the website is visited.
I get the Ready Hit Counters from the different Sites.
But I want the code related to hit counter.
If anybody knows about that please send me the code
or information related to code.
Please...
Thanks
nothing to say.
|
|
|
|