|
-
Mar 5th, 2009, 10:54 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Databound
hi,
i was wondering how can i display the values of a table (Select statement Result) in database in between the html code. but im not getting its way, i got something like databound in searching. but i do not know how to use it and where the connection should be open. because in my requirement i need to write this code in .aspx file not in .cs file.
-
Mar 5th, 2009, 11:33 PM
#2
Thread Starter
Fanatic Member
Re: Databound
also i want to know in the same question that how can i load load data from database table to a html combo box
-
Mar 6th, 2009, 02:53 AM
#3
Re: Databound
Hey,
Are you writing an asp.net application? If so, this should really be posted in the ASP.Net forum.
Have you read up on using ADO.Net? This is how you can get the information from the database into your application. Once you have it there, you can pretty much do anything you want.
Can you explain exactly what it is you are wanting to do?
Gary
-
Mar 6th, 2009, 10:16 AM
#4
Re: Databound
Thread moved to ASP.Net forum
-
Mar 6th, 2009, 01:05 PM
#5
Thread Starter
Fanatic Member
Re: Databound
 Originally Posted by gep13
Hey,
Are you writing an asp.net application? If so, this should really be posted in the ASP.Net forum.
Have you read up on using ADO.Net? This is how you can get the information from the database into your application. Once you have it there, you can pretty much do anything you want.
Can you explain exactly what it is you are wanting to do?
Gary
i will make you clear my problem.
i don't know how can i make my problem clear to you but i will try again.
suppose we have this code in Simple ASP
Code:
<%
' we can open connection here and execute our SQL result into a RecordSet using OLEDB just an example
<html>
<body bgcolor="red">
<h1>Click on the name of student to view his record</h1>
<table>
<tr>
<th>
Student Name
</th>
<th>
Address
</th>
</tr>
<tr>
<td>
<%= RecordSetObj.Field("Student_Name") %>
</td>
<td>
<%= RecordSetObj.Field("Student_Address") %>
</td>
</tr>
</table>
</body>
</html>
%>
in the same way i want to show student name and address in the page. i can write code in .cs file in C# on Visual Studio 2005.
but i dont know how can i do above task in C# because i have to write my code of displaying Dynamic Data between html code. So i m asking you 
pls help
-
Mar 6th, 2009, 02:47 PM
#6
Re: Databound
Hey,
The concept of RecordSet's has now been replaced with the concept of DataSource. If you are using an SQL Server, you may wish to use an SqlDataSource, or, to give you some more control, you may wish to use an ObjectDataSource.
In doing this, use can then bind values on the aspx page to container items with the DataSource to display them on the web page.
Have a read of the links that I posted to, and then if you have an more questions, post back.
Hope this helps!!
Gary
-
Mar 7th, 2009, 05:52 AM
#7
Thread Starter
Fanatic Member
Re: Databound
i read that and im able to connect my Sqldatasource to GridView but i want to keep a QueryString Variable.
Suppose my Sql is
Code:
Select id, first_name, address from Students
now i want to have a query string On Student(S) name so it will jump to another page and other page will process its task by the requested querystring.
like this
Code:
<asp:GridView ID="Grid1" DataSourceID="SqlDataSource1" runat="server" Width="424px" BackColor="Aqua" Caption="My Grid View" CellPadding="0" CellSpacing="0">
<Columns>
<asp:BoundField DataField="id" HeaderText="USER ID" />
<asp:BoundField DataField="address" HeaderText="Category name" />
<asp:HyperLinkField DataTextField="first_name" DataNavigateUrlFormatString="new_page.aspx?id='" + DataNavigateUrlFields="id" + "'" />
</Columns>
</asp:GridView>
everything works fine for me but i don't know how can i create successful QueryString URL in above Red Line.
thanks Gary for your help
-
Mar 7th, 2009, 06:00 AM
#8
Re: Databound
Hey,
You should be able to do something like the following:
Code:
<asp:hyperlinkfield datatextfield="first_name"
datanavigateurlfields="id"
datanavigateurlformatstring="new_page.aspx?id={0}" />
You can find more information about this here:
http://msdn.microsoft.com/en-us/libr...matstring.aspx
Hope that helps!!
Gary
-
Mar 7th, 2009, 06:09 AM
#9
Thread Starter
Fanatic Member
Re: Databound
very nice help gary 
this could my last question what is the meaning of RED text in below code
Code:
<asp:hyperlinkfield datatextfield="first_name"
datanavigateurlfields="id"
datanavigateurlformatstring="new_page.aspx?id={0}" />
this is what i was looking for it works fine for me. but i still want to ask what does it mean {0}
why only 0 ?
and another question is i want to display only selected fields data in the GridView but it shows all the fields how i can do it?
-
Mar 7th, 2009, 06:15 AM
#10
Re: Databound
Hey,
{0} is basically a placeholder for text that will be put into there. This technique is used a lot using String.Format. You can have a look here:
http://msdn.microsoft.com/en-us/library/fht0f5be.aspx
You during the Data Binding of the page, it basically takes this:
new_page.aspx?id={0}
and say, I am going to replace {0} with the ID of the current student.
It starts at 0 since this is the first item that you would pass into a String.Format. An example might help here:
Code:
Dim test1 As String = "Hello"
Dim test2 As String = "World"
MessageBox.Show(String.Format("{0} {1}", test1, test2)
This results in a MessageBox showing "Hello World", since I am passing in test1 as the first parameter and test2 as the second.
I hope that makes sense!
As for your second question, you should be able to do this through the designer. Click on the small triangle at the top right of the GridView and I think the option is "Edit Columns".
Gary
-
Mar 7th, 2009, 06:29 AM
#11
Thread Starter
Fanatic Member
Re: Databound
right in edit columns this option was Auto Generate Fields Check Box on the bottom left
-
Mar 7th, 2009, 06:33 AM
#12
Re: [RESOLVED] Databound
Hey,
Normally what I do is de-select the Auto-generate fields, and only add in the fields that I want. In your case, you want the ID and Name, but I am guessing that you don't want the ID to be visible. Is that right?
In your case, just set the visible status of the ID field to False and that should do the trick.
Gary
-
Mar 7th, 2009, 06:35 AM
#13
Thread Starter
Fanatic Member
Re: [RESOLVED] Databound
but why it does not work
Code:
<asp:ListBox
id="ListBox1"
runat="server"
DataSourceID="SqlDataSource1">
</asp:ListBox>
just shows
System.Data.Common.DbDataRecord
in Listbox
-
Mar 7th, 2009, 06:37 AM
#14
Thread Starter
Fanatic Member
Re: [RESOLVED] Databound
 Originally Posted by gep13
Hey,
Normally what I do is de-select the Auto-generate fields, and only add in the fields that I want. In your case, you want the ID and Name, but I am guessing that you don't want the ID to be visible. Is that right?
In your case, just set the visible status of the ID field to False and that should do the trick.
Gary
yes i got it working as you said thanks so much bro
-
Mar 7th, 2009, 06:38 AM
#15
Re: [RESOLVED] Databound
 Originally Posted by chunk
but why it does not work
Code:
<asp:ListBox
id="ListBox1"
runat="server"
DataSourceID="SqlDataSource1">
</asp:ListBox>
just shows
System.Data.Common.DbDataRecord
in Listbox
Hey,
Have a look at the following:
http://msdn.microsoft.com/en-us/libr...77(VS.80).aspx
I believe you need to set the DataTextField and the DataValueField properties.
Gary
-
Mar 7th, 2009, 12:42 PM
#16
Thread Starter
Fanatic Member
Re: [RESOLVED] Databound
thanks bro it works now
-
Mar 7th, 2009, 03:23 PM
#17
Re: [RESOLVED] Databound
Good stuff, glad to hear it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|