Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 18th, 2005, 09:13 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Grid

Hi, I want to use datagrid display book records. in that table hv an action column that enable user to reserve the book. i want to put the action column rightmost in table, but it always is the leftmost, how can I do that?

Thanks!

Irene

 
Old May 18th, 2005, 10:47 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The grid is putting the action column you have defined first and putting the automatically generated columns after it. You need to explicitly define all the columns you wish to see in the grid inside of the <columns> node in the datagrid markup. Then you need to set the attribute "AutoGenerateColumns" to false.

-Peter
 
Old May 19th, 2005, 02:47 AM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I can display the data grid already. but my data in the database is not displayed. I have created the connection to database, data adapter and fill dataset with the data. What caused that happen?

Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        SqlDataAdapter1.Fill(DsBook11)
        DataGridNo.Text = CStr(DataBinder.Eval(DsBook11, "Tables{Material_Table1].DefaultView.[0].seqNo"))
        DataGridTitle.Text = CStr(DataBinder.Eval(DsBook11, "Tables{Material_Table1].DefaultView.[0].Title"))

End Sub
Thanks!

Irene


 
Old May 19th, 2005, 05:56 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You don't need to use all that databinder eval stuff in codebehind. That syntax is for inline databinding syntax in the page markup. The syntax you have is incorrect:

Change this:
DataGridNo.Text = CStr(DataBinder.Eval(DsBook11, "Tables{Material_Table1].DefaultView.[0].seqNo"))
DataGridTitle.Text = CStr(DataBinder.Eval(DsBook11, "Tables{Material_Table1].DefaultView.[0].Title"))

To this:
DataGridNo.Text = DsBook11.Tables["Material_Table1"].DefaultView.[0].seqNo.ToString();
DataGridTitle.Text = DsBook11.Tables["Material_Table1"].DefaultView.[0].Title.ToString();

What are these controls? Are these labels or textboxes? I'm confused by your naming. The thread started with a question about the datagrid, but you seem to now be asking about some other control.

-Peter
 
Old May 19th, 2005, 07:15 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I use datagrid n dataset. now what i get is empty table without the data.

How can I declare the DataGridNo n DataGridTitle in code behind page?

 
Old May 19th, 2005, 07:33 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I still don't understand. What are the DataGridNo and DataGridTitle controls?

You can assign values to those controls in the codebehind like I showed in my previous post.

-Peter
 
Old May 19th, 2005, 08:58 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i use datagrid. n the ID of it is DataGridBook, n it has 2 columns, 1 is No, another is Title. What I want to do is to bind the values in database to that 2 columns.

 
Old May 19th, 2005, 09:10 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You need to set up your datagrid appropriately:

<asp:datagrid runat="server" id="DataGridBook">
   <columns>
      <asp:boundcolumn datafield="No" />
      <asp:boundcolumn datafield="Title" />
   </columns>
</asp:datagrid>

Then you can bind to it:

SqlDataAdapter1.Fill(DsBook11)
DataGridBook.DataSource = DsBook11
DataGridBook.DataBind()

You don't need to set up the column binding in the codebehind, that is done in the column definitions in the datagrid markup.

-Peter
 
Old May 19th, 2005, 11:11 PM
Authorized User
 
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I try out ur suggestion. But now i getting following errors:

Server Error in '/e-library' Application.
--------------------------------------------------------------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'DsBook11' is not declared.

Source Error:



Line 13: <asp:Label id="lblBoks" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 32px" runat="server"
Line 14: Width="104px" Height="8px" Font-Bold="True" Font-Size="Larger">Book List</asp:Label>
Line 15: <asp:DataGrid id=DataGridBook style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server" Height="329px" Width="594px" AutoGenerateColumns="False" AllowPaging="True" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" DataSource="<%# DsBook11 %>" DataMember="Material_Table1" >
Line 16: <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
Line 17: <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>


Source File: c:\inetpub\wwwroot\e-library\Borrow1.aspx Line: 15

[HTML code]
<asp:DataGrid id=DataGridBook style="Z-INDEX: 102; LEFT: 16px; POSITION: absolute; TOP: 72px" runat="server" Height="329px" Width="594px" AutoGenerateColumns="False" AllowPaging="True" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" BackColor="White" CellPadding="4" DataSource="<%# DsBook11 %>" DataMember="Material_Table1" >

<Columns>
    <asp:BoundColumn HeaderText="No" DataField="No"></asp:BoundColumn> <asp:BoundColumn HeaderText="Title" DataField="Title"></asp:BoundColumn>
    <asp:ButtonColumn Text="Reserve" HeaderText="Action" CommandName="Reserve"></asp:ButtonColumn>
</Columns>
</asp:DataGrid>
[/HTML code]

I declare the DsBook11 already, why have this error?

Thanks!

 
Old May 20th, 2005, 01:00 AM
Authorized User
 
Join Date: Jul 2004
Posts: 88
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You need not write this in the html:
DataSource="<%# DsBook11 %>"

Just follow Peter's last post.
Then you can bind to it:

SqlDataAdapter1.Fill(DsBook11)
DataGridBook.DataSource = DsBook11
DataGridBook.DataBind()

You need to write the binding part in the codebehind






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to sort data in a data grid? zaheerabbas.sk ASP.NET 1.0 and 1.1 Basics 3 April 10th, 2007 02:37 PM
Export data from data grid to excel pomoc VB.NET 2002/2003 Basics 0 December 16th, 2005 03:11 PM
Export data from data grid to Excel pomoc Visual Basic 2005 Basics 0 December 16th, 2005 02:56 PM
trying to load db data into data grid itsajourney Beginning VB 6 2 June 7th, 2005 12:05 PM
About data grid Asteroid ASP.NET 1.0 and 1.1 Basics 4 December 9th, 2004 05:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.