Best advice needed navigation/display through dataset on one page

Discussion in 'ASP .Net Web Controls' started by janetb, May 5, 2006.

  1. janetb

    janetb Guest

    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.SelectCommand.Parameters.Add(w_ID)
    da.Fill(ds, "pages")
    dgNavList.DataSource=ds.tables("pages")
    dgNavList.DataBind()
    End Sub

    Sub chgPage(Sender As Object, E As DataGridCommandEventArgs)
    varBkm=e.Item.ItemIndex
    txtBkm.text=varBkm
    lblPgTitle.text=ds.tables("pages").rows(varBkm).item(2)
    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
    response.redirect("login.asp")
    else
    varWid=request("wid")
    varPid=request("pid")
    txtPID.text=varPid
    txtWID.text=varWid
    if request("bkm")="" then varBkm=0 else varBkm=cint(request("bkm"))
    txtBkm.text=varBkm
    end if
    bindNav()
    End If
    end sub

    </script>

    <form id="Form1" method="post" runat="server">
    <asp:datagrid id="dgNavList" onEditCommand="chgPage"
    autogenerateColumns="False" runat="server">
    <Columns>
    <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" />
    </Columns>
    </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 />
    </form>
    <html>
    <body
     
    janetb, May 5, 2006
    #1
    1. Advertising

  2. janetb

    janetb Guest

    Have everything now working except one thing. I'm making 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)
    dgNavList.selectedIndex=n
    lblPgTitle.text=dgNavList.item.cells(1).text
    end sub

    Many thanks for any help.... Janet


    "janetb" wrote:

    > 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.SelectCommand.Parameters.Add(w_ID)
    > da.Fill(ds, "pages")
    > dgNavList.DataSource=ds.tables("pages")
    > dgNavList.DataBind()
    > End Sub
    >
    > Sub chgPage(Sender As Object, E As DataGridCommandEventArgs)
    > varBkm=e.Item.ItemIndex
    > txtBkm.text=varBkm
    > lblPgTitle.text=ds.tables("pages").rows(varBkm).item(2)
    > 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
    > response.redirect("login.asp")
    > else
    > varWid=request("wid")
    > varPid=request("pid")
    > txtPID.text=varPid
    > txtWID.text=varWid
    > if request("bkm")="" then varBkm=0 else varBkm=cint(request("bkm"))
    > txtBkm.text=varBkm
    > end if
    > bindNav()
    > End If
    > end sub
    >
    > </script>
    >
    > <form id="Form1" method="post" runat="server">
    > <asp:datagrid id="dgNavList" onEditCommand="chgPage"
    > autogenerateColumns="False" runat="server">
    > <Columns>
    > <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" />
    > </Columns>
    > </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 />
    > </form>
    > <html>
    > <body
    >
     
    janetb, May 9, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Laurahn
    Replies:
    3
    Views:
    918
    Steven Cheng[MSFT]
    Feb 6, 2007
  2. etienno
    Replies:
    0
    Views:
    612
    etienno
    Dec 13, 2006
  3. Bobby Edward
    Replies:
    7
    Views:
    394
    Bobby Edward
    Feb 22, 2008
  4. Alan Z. Scharf

    Single record display paging through dataset

    Alan Z. Scharf, Jul 22, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    242
    Lewis Wang [MSFT]
    Jul 23, 2003
  5. June Moore
    Replies:
    1
    Views:
    113
    Spats30
    Feb 9, 2005
Loading...

Share This Page