Err when creating link to each line of grid??

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Err when creating link to each line of grid??

    Hi,
    I am having err when creating link to each line of grid at LINE 38. My
    objective in asp.net is: each line can be linked to page with your
    parameters as VB 5/6, Delphi 5/6/7, etc....
    See the code bellow:
    Thanks!
    ---------------------------------------
    Vilmar Brazão de Oliveira
    HI-TEC Informática

    <%@ Page Language="vb" Debug="true" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

    <script language="VB" runat="server">
    Sub Page_Load(sender as Object, e as EventArgs)
    Dim connString as String 'Create a connection string
    connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &
    Server.MapPath("Northwind.mdb")
    'C:\Arquivos de programas\Microsoft Office\Office\Samples\Northwind.mdb

    'Open a connection
    Dim objConnection as OleDbConnection
    objConnection = New OleDbConnection(connString)
    objConnection.Open()

    'Specify the SQL string
    Dim strSQL as String = "SELECT * FROM Clientes"

    'Create a command object
    Dim objCommand as OleDbCommand
    objCommand = New OleDbCommand(strSQL, objConnection)

    'Get a datareader
    Dim objDataReader as OleDbDataReader
    objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)

    'Do the DataBinding
    dgResults.DataSource = objDataReader
    dgResults.DataBind()

    'Close the datareader/db connection
    objDataReader.Close()

    'Montagem de link.
    Dim I as Double
    Dim Registro as String

    For I = 0 To Me.dgResults.Items.Count - 1
    Dim NomeLink As LinkButton =
    CType(datagrid.Items(i).FindControl("NomeLink"), LinkButton) 'LINHA 38
    Registro = Tabela.Rows(I)
    lnkEdita.CommandArgument = "Param=" & valor
    Next
    End Sub

    Sub myItems_ItemDataBound(ByVal Sender As Object, ByVal e As
    DataGridItemEventArgs)
    dgResults.Attributes.Add("onClick","JavaScript:ale rt('texto');")

    If e.Item.ItemType = ListItemType.Item Then
    e.Item.Attributes.Add("onmouseover",
    "this.style.backgroundColor='#EEEEEE'")
    e.Item.Attributes.Add("onmouseout",
    "this.style.backgroundColor='#F7EFC6'")
    ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then
    e.Item.Attributes.Add("onmouseover",
    "this.style.backgroundColor='#EEEEEE'")
    e.Item.Attributes.Add("onmouseout",
    "this.style.backgroundColor='#F7EFC6'")
    End If
    End Sub

    Protected Sub EventoNoClick(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.CommandEventArgs)
    Response.Redirect("SeuAspx.aspx?" & e.CommandArgument)
    End Sub

    'FFFFEF »»um tom de amarelo bem claro.
    'F7EFC6 »»um tom de amarelo meio ocre.
    </script>

    <html>

    <head>
    <title>Exemplo consulta com ASP.Net - 02</title>
    </head>

    <body text="#000000" bgcolor="#ffffff">
    <h1>Exemplo consulta com ASP.Net - 01</h1>

    <asp:DataGrid
    id="dgResults" runat="server" Width="700" BackColor="#F7EFC6"
    BorderColor="black"
    ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana"
    Font-Size="8pt"
    HeaderStyle-BackColor="#ffaad" OnItemDataBound="myItems_ItemDataBound">
    </asp:DataGrid>

    <asp:TemplateColumn HeaderText="Assunto">
    <ItemStyle width="33%"></ItemStyle>
    <ItemTemplate>
    <asp:LinkButton id="NomeLink" runat="server" OnCommand="EventoNoClick"
    Font-Size="9pt"
    Text='<%# DataBinder.Eval(DataSet, "Tables[Tabela].DefaultView.[0].Campo")
    %>'>
    </asp:LinkButton>
    </ItemTemplate>
    </asp:TemplateColumn>

    </body>
    </html>


    Vilmar Brazão de Oliveira Guest

  2. Similar Questions and Discussions

    1. New Line in Flash Grid
      Anyone know how to enter a newline "#Chr(13)#"&"#Chr(10)#" into <cfgrid selectmode="edit"...> what I'm trying to do is to edit a single grid box...
    2. How do you change the vertical grid line color of the header in a datagrid???
      Hi, I managed to change the vertical grid line color for all the rows, but can't get it to work for the header as well. Any help? Thanks
    3. Adding a href link to a column in a data grid
      Hi, I am trying to figure out how I can add a html link to a value (which is the virtual path of a file) in the data grid column. I have code as...
    4. ASP.Net Grid Control Link Button
      In an ASP.NET page that has a data grid with a bound column of link button. How can I reference the control and set properties for the link button...
    5. Grid Line Color
      How does one change the color of the lines between items in a datagrid? I've played with every css style I can find and nothing works. -Brett-
  3. #2

    Default Re: Err when creating link to each line of grid??

    I found a solution:
    Vilmar Brazão de Oliveira
    -----------------------------

    <%@ Page Language="vb" Debug="true" %>
    <%@ Import Namespace="System" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>

    <script language="VB" runat="server">
    Sub Page_Load(sender as Object, E As EventArgs)
    Dim connString as String 'Create a connection string
    connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &
    Server.MapPath("Northwind.mdb")
    'C:\Arquivos de programas\Microsoft Office\Office\Samples\Northwind.mdb

    'Open a connection
    Dim objConnection as OleDbConnection
    objConnection = New OleDbConnection(connString)
    objConnection.Open()

    'Specify the SQL string
    Dim strSQL as String = "SELECT * FROM Clientes"

    'Create a command object
    Dim objCommand as OleDbCommand
    objCommand = New OleDbCommand(strSQL, objConnection)

    'Get a datareader
    Dim objDataReader as OleDbDataReader
    objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)

    'Do the DataBinding
    dtgResultados.DataSource = objDataReader
    dtgResultados.DataBind()

    'Close the datareader/db connection
    objDataReader.Close()
    End Sub

    Sub myItems_ItemDataBound(ByVal Sender As Object, ByVal E As
    DataGridItemEventArgs)
    ' dtgResultados.Attributes.Add("onClick","JavaScript :alert('texto');")

    'FFFFEF »»um tom de amarelo bem claro.
    'F7EFC6 »»um tom de amarelo meio ocre.
    If e.Item.ItemType = ListItemType.Item Then
    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#EEEEEE'")
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7EFC6'")
    ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then
    e.Item.Attributes.Add("onmouseover", "this.style.backgroundColor='#EEEEEE'")
    e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7EFC6'")
    End If
    End Sub

    Sub Enviar(ByVal Sender As Object, ByVal E As CommandEventArgs)
    Dim strNomeDaEmpresa As String = E.CommandArgument
    Response.Redirect("teste_passagem_parametro_por_da tagrid.aspx?Parametro=" &
    strNomeDaEmpresa)
    End Sub
    </script>

    <html>

    <head>
    <title>Exemplo consulta com ASP.Net - 03 - Linhas Clic&aacute;veis com
    LinkButton</title>
    </head>

    <body text="#000000" bgcolor="#ffffff">

    <h1>Exemplo consulta com ASP.Net - 03 - Linhas Clicáveis com LinkButton</h1>
    <form id="frmParametros" enctype="application/x-www-form-urlencoded"
    runat="server">
    <asp:DataGrid id="dtgResultados" runat="server" AutoGenerateColumns="False"
    Width="100%" BackColor="#F7EFC6" BorderColor="black" ShowFooter="false"
    CellPadding="3" CellSpacing="0"
    Font-Name="Verdana" Font-Size="8pt" HeaderStyle-BackColor="#ffaad"
    OnItemDataBound="myItems_ItemDataBound">
    <Columns>
    <asp:BoundColumn DataField="CódigoDoCliente" HeaderText="Cód. Cliente"
    HeaderStyle-Width="75"></asp:BoundColumn>
    <asp:BoundColumn DataField="NomeDaEmpresa" HeaderText="Nome
    Empresa"></asp:BoundColumn>
    <asp:BoundColumn DataField="NomeDoContato" HeaderText="Nome
    Contato"></asp:BoundColumn>
    <asp:BoundColumn DataField="CargoDoContato" HeaderText="Cargo
    Contato"></asp:BoundColumn>
    <asp:TemplateColumn HeaderStyle-Width="20px" HeaderText="Editar">
    <ItemTemplate>
    <asp:linkbutton id="lnkEditar" text="Botão de link" CommandArgument='<%#
    DataBinder.Eval(Container.DataItem, "NomeDaEmpresa") %>' OnCommand="Enviar"
    Runat="server"></asp:linkbutton>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>
    </form>

    </body>
    </html>
    "Vilmar Brazão de Oliveira" <xx@xx.com.br.xx> escreveu na mensagem
    news:O6JuJgIWEHA.2996@TK2MSFTNGP12.phx.gbl...
    > Hi,
    > I am having err when creating link to each line of grid at LINE 38. My
    > objective in asp.net is: each line can be linked to page with your
    > parameters as VB 5/6, Delphi 5/6/7, etc....
    > See the code bellow:
    > Thanks!
    > ---------------------------------------
    > Vilmar Brazão de Oliveira
    > HI-TEC Informática
    >
    > <%@ Page Language="vb" Debug="true" %>
    > <%@ Import Namespace="System.Data" %>
    > <%@ Import Namespace="System.Data.OleDb" %>
    >
    > <script language="VB" runat="server">
    > Sub Page_Load(sender as Object, e as EventArgs)
    > Dim connString as String 'Create a connection string
    > connString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" &
    > Server.MapPath("Northwind.mdb")
    > 'C:\Arquivos de programas\Microsoft Office\Office\Samples\Northwind.mdb
    >
    > 'Open a connection
    > Dim objConnection as OleDbConnection
    > objConnection = New OleDbConnection(connString)
    > objConnection.Open()
    >
    > 'Specify the SQL string
    > Dim strSQL as String = "SELECT * FROM Clientes"
    >
    > 'Create a command object
    > Dim objCommand as OleDbCommand
    > objCommand = New OleDbCommand(strSQL, objConnection)
    >
    > 'Get a datareader
    > Dim objDataReader as OleDbDataReader
    > objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConn ection)
    >
    > 'Do the DataBinding
    > dgResults.DataSource = objDataReader
    > dgResults.DataBind()
    >
    > 'Close the datareader/db connection
    > objDataReader.Close()
    >
    > 'Montagem de link.
    > Dim I as Double
    > Dim Registro as String
    >
    > For I = 0 To Me.dgResults.Items.Count - 1
    > Dim NomeLink As LinkButton =
    > CType(datagrid.Items(i).FindControl("NomeLink"), LinkButton) 'LINHA 38
    > Registro = Tabela.Rows(I)
    > lnkEdita.CommandArgument = "Param=" & valor
    > Next
    > End Sub
    >
    > Sub myItems_ItemDataBound(ByVal Sender As Object, ByVal e As
    > DataGridItemEventArgs)
    > dgResults.Attributes.Add("onClick","JavaScript:ale rt('texto');")
    >
    > If e.Item.ItemType = ListItemType.Item Then
    > e.Item.Attributes.Add("onmouseover",
    > "this.style.backgroundColor='#EEEEEE'")
    > e.Item.Attributes.Add("onmouseout",
    > "this.style.backgroundColor='#F7EFC6'")
    > ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then
    > e.Item.Attributes.Add("onmouseover",
    > "this.style.backgroundColor='#EEEEEE'")
    > e.Item.Attributes.Add("onmouseout",
    > "this.style.backgroundColor='#F7EFC6'")
    > End If
    > End Sub
    >
    > Protected Sub EventoNoClick(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.CommandEventArgs)
    > Response.Redirect("SeuAspx.aspx?" & e.CommandArgument)
    > End Sub
    >
    > 'FFFFEF »»um tom de amarelo bem claro.
    > 'F7EFC6 »»um tom de amarelo meio ocre.
    > </script>
    >
    > <html>
    >
    > <head>
    > <title>Exemplo consulta com ASP.Net - 02</title>
    > </head>
    >
    > <body text="#000000" bgcolor="#ffffff">
    > <h1>Exemplo consulta com ASP.Net - 01</h1>
    >
    > <asp:DataGrid
    > id="dgResults" runat="server" Width="700" BackColor="#F7EFC6"
    > BorderColor="black"
    > ShowFooter="false" CellPadding="3" CellSpacing="0" Font-Name="Verdana"
    > Font-Size="8pt"
    > HeaderStyle-BackColor="#ffaad" OnItemDataBound="myItems_ItemDataBound">
    > </asp:DataGrid>
    >
    > <asp:TemplateColumn HeaderText="Assunto">
    > <ItemStyle width="33%"></ItemStyle>
    > <ItemTemplate>
    > <asp:LinkButton id="NomeLink" runat="server" OnCommand="EventoNoClick"
    > Font-Size="9pt"
    > Text='<%# DataBinder.Eval(DataSet,
    "Tables[Tabela].DefaultView.[0].Campo")
    > %>'>
    > </asp:LinkButton>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > </body>
    > </html>
    >
    >

    Vilmar Brazão de Oliveira Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139