Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 5th, 2006, 09:24 AM
Authorized User
Join Date: May 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid - selected item display advice

I'm trying to create a page that has a menu down the left side with one field within the dataset displaying, but clickable. OnClick, I'd like to have items displayed to the right (since one field is a pointer to an image, is it better to response.write or use a label?). I've tried using a datagrid with a dataset, but the buttonColumn doesn't let you dictate the text display from an item in the dataset? And, I can't get it to reflect to the right. I'd apprciate any advice. I'm giving it a shot, but I'm not getting very far.

<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Data" %>
<%@Page Language="VB" debug="True"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script language="vb" runat="server">
Public strConn As String = "connection string stuff;" 
Public cn As New SqlClient.SqlConnection(strConn)
Public cmd as sqlclient.sqlCommand
Public ds as New Dataset
Public varBkm as integer, varWID as integer, varPID as integer

Sub bindNav()
  dim ds as New Dataset
  Dim da as New SQLDataAdapter
  da = New SqlDataAdapter("sp_eCoursePage", cn) 
  da.SelectCommand.CommandType = CommandType.StoredProcedure 
  Dim w_ID as New SqlParameter("@ID",varWid) 
  da.Fill(ds, "pages")
End Sub

Sub chgPage(Sender As Object, E As DataGridCommandEventArgs)
end sub

Sub Page_load(sender as Object, e as EventArgs)
  If Not (IsPostBack)
    if request("pid")="" or request("pid")="0" or request("wid")="" or request("wid")="0" then 
      if request("bkm")="" then varBkm=0 else varBkm=cint(request("bkm"))
    end if
  End If
end sub


<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgNavList" onEditCommand="chgPage" autogenerateColumns="False" runat="server">
  <asp:BoundColumn DataField="pageID_pk" Visible="False"></asp:BoundColumn>
  <asp:BoundColumn DataField="pgTitle" Visible="False"></asp:BoundColumn>
  <asp:BoundColumn DataField="pgDesc" Visible="False"></asp:BoundColumn>
  <asp:BoundColumn DataField="navTitle"></asp:BoundColumn>
  <asp:ButtonColumn Text="Edit" CommandName="Edit" />
</asp:DataGrid><br />    
pid: <asp:label id="txtPID" runat="server" visible="true" /><br />
wid: <asp:label id="txtWID" runat="server" visible="true" /><br />
bkm: <asp:label id="txtBkm" runat="server" visible="true" /><br />
<asp:Button id="btnChange" runat="server" Text="Update" /><br />

page title: <asp:label id="lblPgTitle" runat="server" />

<% 'response.write(ds.Tables("pages").Rows(CInt(varBkm)).Item(3)) %><br />
page image: <% 'response.write(ds.Tables("pages").Rows(CInt(varBkm)).Item(4)) %><br />
page content: <% 'response.write(ds.Tables("pages").Rows(CInt(varBkm)).Item(5)) %><br />
  #2 (permalink)  
Old May 9th, 2006, 11:40 AM
Authorized User
Join Date: May 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

Everything's working except the first, last, next, prev buttons that are outside of the datagrid. The labels/buttons that are assigned value/commands respectively based on which row of the datagrid is selected. Then, if the button outside the datagrid is pushed, I want it to go to the correct row of the datagrid and display a hidden cell of the datagrid in a label field. What is the correct syntax for pulling a datagrid's hidden column based on a button click outside of the datagrid? If you look at the code below, the correct row in the datagrid is highlighted when I push the next button, but I can't get the syntax right to have the lblPgTitle display the hidden cell of the datagrid. (datagrid cell specifically is DataField="pgTitle")

sub pgNext(sender as object, e as eventArgs)
    dim n as integer=cint(lblNext.text)
end sub

Many thanks for any help.... Janet
  #3 (permalink)  
Old May 9th, 2006, 02:56 PM
Authorized User
Join Date: May 2006
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts

Clarification: I'm using the datagrid like a table of contents, then just want to reflect some non-visible boundColumns when the index changes for a label web control that's not within the datagrid. I don't need to run sql to get and rebind the dataset, since I'm displaying the whole dataset as a table of contents. I'm just trying to figure out the syntax so that when the index changes in the datagrid, I take the first cell and place the text into a label. Can't use datakeys, because the order is set by the data entry person, so next, prev would be screwed up. Really need to use index property?

Tried to switch gears a little, since I'm getting the selected index changed above with the buttons -using the OnSelectedIndexChanged="navNav"

Sub navNav(Sender as object, e as eventArgs)
  Dim itemTitle As TableCell = dgNavList.Items[dgNavList.SelectedIndex].Cells(1)
End Sub

Any other ideas?


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Display data as per combobox item selected yogeshyl Excel VBA 0 July 28th, 2007 06:17 AM
display datagrid item shwetarani2002 ASP.NET 1.0 and 1.1 Basics 1 July 16th, 2007 07:47 AM
How Refer to Selected Item in DataGrid Morfoman General .NET 0 September 20th, 2005 11:41 AM
re: DataGrid Selected Item from outside grid vids ASP.NET 1.x and 2.0 Application Design 1 May 2nd, 2005 04:12 PM
Datagrid - Scroll to selected item rodmcleay ASP.NET 1.0 and 1.1 Professional 2 February 21st, 2005 08:36 PM

All times are GMT -4. The time now is 07:13 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.