Results 1 to 17 of 17

Thread: [RESOLVED] Databound

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

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

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    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

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Databound

    Thread moved to ASP.Net forum

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Unhappy Re: Databound

    Quote 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

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    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

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    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?

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: Databound

    right in edit columns this option was Auto Generate Fields Check Box on the bottom left

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    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

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: [RESOLVED] Databound

    Quote 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

  15. #15
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] Databound

    Quote 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

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: [RESOLVED] Databound

    thanks bro it works now

  17. #17

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width