99 messaggi dal 21 aprile 2007
Salve
mi chiedevo come faccio ad aprire in dettaglio un record che ottengo da un datalist di ricerca, in un altra pagina?


FACCIO UN ESEMPIO :

ricerca:

risultati ricerca scrivendoli in un datalist:

RECORD 1 .. HYPERLINK 1
RECORD 2 .. HYPERLINK 2
RECORD 3 .. HYPERLINK 3



VOGLIO OTTENERE HE CLICCANDO SUI RELATIVI HYPERLINK DEL RECORD
MI SI APRA UN'ALTA PAGINA HTML CON I DETTAGLI IMPAGINATI MEGLIO
DEL RELATIVO RECORD!nella pagina _blank se uso ugualmente un datalist
come faccio a dirgli di prendere il record con il releativo ID indicato
nell hyperlink nella pagina di ricerca?
Tramite Request.QueryString

Il link del datalist sara miaDir/dettaglio.aspx?pkDettaglio=xx

oppure utilizzi UrlRewriting e passi il nome della categoria

quindi miaDir/NomeCategoria.aspx

Fabrizio Canevali
99 messaggi dal 21 aprile 2007
ma nella pagina dettaglio devo cmq implementare un datalist?
non ci sono script di esempio in giro?
331 messaggi dal 06 maggio 2003
Passi l'ID tramite querystring, poi recuperi i dati e li butti in un Datareader e poi ti leggi i dati stampandoli dove ti servono ...

scrivo 2 righe buttandole così

OdbcConnection connDB;

string strConnectionStringODBC;

connDB = new OdbcConnection();
connDB.ConnectionString = strConnectionStringODBC;
connDB.Open();

String strSql = "SELECT * FROM tabella WHERE ID = " idrecuperatodaquerystring
OdbcDataReader odDataReader;
OdbcCommand odCmd;
odCmd = new OdbcCommand(strSql, connDB);
odDataReader = odCmd.ExecuteReader();

lbl1.text = odDataReader["colonna1"].toString();
lbl2.text = odDataReader["colonna2"].toString();
lbl3.text = odDataReader["colonna3"].toString();

connDB.Close();
99 messaggi dal 21 aprile 2007
quindi nella pagina che contiene l hyperlink devo solo dichiarare l oggetto request.QueryString?
331 messaggi dal 06 maggio 2003
idpassato = Request.QueryString["id"]

dove ID è ovviamente la chiave che usi quando inserisci il link:

pagina.aspx?id=valore
99 messaggi dal 21 aprile 2007
Salve ragazzi
nn tiesco a risolvere..nella pagina del Datalist ho fatto così :


<script>
Request.QueryString.Get("Doc_ID");
</script>


<asp:HyperLink ID="HyperLink1" Runat="server" 
NavigateUrl=<%# "~/dettagli.aspx?Doc_ID=" + DataBinder.Eval(Container.DataItem, "Doc_ID") %>> VEDI </asp:Hyperlink>
              


nella pagina dettagli.aspx :

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    
SqlConnection myConnection;

string strConnectionString;
    
protected void Page_Load(Object Src, EventArgs E) 
{

myConnection = new SqlConnection("");
myConnection.ConnectionString = strConnectionString;
myConnection.Open();

String strSql = "SELECT * FROM upload WHERE Doc_ID = @Doc_ID ";

Request.QueryString.Get("Doc_ID");   
    
SqlDataReader odDataReader;
SqlCommand odCmd;
odCmd = new SqlCommand(strSql, myConnection);
odDataReader = odCmd.ExecuteReader();

lbl1.text = odDataReader["Nome"].toString();
lbl2.text = odDataReader["Cognome"].toString();
lbl3.text = odDataReader["Titolo"].toString();

myConnection.Close();
         
     }
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <ItemTemplate>
           
                
                
                <b>Autore:</b><br />
                <asp:Label ID="lbl1" runat="server" Width="100" Text='<%# Eval("Nome") %>'></asp:Label>
                <asp:Label ID="lbl2" runat="server" Width="100" Text='<%# Eval("Cognome") %>'></asp:Label>
                <asp:Label ID="lbl3" runat="server" Width="100" Text='<%# Eval("Titolo") %>'></asp:Label>
    </div>
    </form>
</body>
</html>



ma mi da questo errore :


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: CS0117: 'System.Web.UI.WebControls.Label' does not contain a definition for 'text'

Source Error:

 

Line 27: odDataReader = odCmd.ExecuteReader();
Line 28: 
Line 29: lbl1.text = odDataReader["Nome"].toString();
Line 30: lbl2.text = odDataReader["Cognome"].toString();
Line 31: lbl3.text = odDataReader["Titolo"].toString();
 

Source File: c:\Inetpub\wwwroot\tesi\dettagli.aspx    Line: 29 



dove sbaglio?
652 messaggi dal 21 gennaio 2007
Contributi
la proprietà Text di un controllo Label, è con la L maiuscola innanzitutto ! cmq, l'errore è di fondo.
nella parte di markup devi inserire un controllo di tipo Data-Bound, come per esempio un DetailsView, FormView, Repeater, DataList, ecc... fatto questo, nella parte di code-behind devi effettuare il bind dei dati su tale controllo.
una cosa di questo genere:

myConnection = new SqlConnection("");
myConnection.ConnectionString = strConnectionString;
myConnection.Open();

String strSql = "SELECT * FROM upload WHERE Doc_ID = " +
Request.QueryString.Get("Doc_ID");

SqlCommand odCmd;
odCmd = new SqlCommand(strSql, myConnection);
SqlDataAdapter adapter = new SqlDataAdapter(odCmd);
DataTable dt = new DataTable();
adapter.Fill(dt);
formView.DataSource = dt;
formView.DataBind();
myConnection.Close();

<FormVew id="formView" runat="server">
<ItemTemplate>
Autore: <asp:Label ID="lbl1" runat="server" Width="100"><%# Eval("Nome") %></asp:Label>
Cognome: <asp:Label ID="lbl2" runat="server" Width="100"><%# Eval("Cognome") %></asp:Label>
Titolo: <asp:Label ID="lbl3" runat="server" Width="100" ><%# Eval("Titolo") %></asp:Label>
</ItemTemplate>
</FormView>

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.