Ciao a tutti, ho ancora bisogno del vostro aiuto...a quanto pare non riesco proprio ad entrare nella logica di aspx, forse sono troppo vecchio per imparare nuovi linguaggi :-(
Espongo lo scenario, sperando di essere sufficientemente chiaro: ho una pagina products.aspx in cui bindo dei dati che arrivano da un DB Access, e poi una pagina products.aspx.vb con del codebehind che viene richiamato dalla pagina products.aspx
I dati vengono esposti in tabella dal codebehind (a cui mi devo appoggiare per particolari esigenze di formattazione/raggruppamento). Il problema specifico riguarda il campo DESC_SFAM a cui è associata una css class "desc_sfam"; la classe funziona correttamente, ma quando si verifica l'evento che dovrebbe cambiarla, non riesco a riferirmi a quello specifico campo, in quanto la tabella viene vista come intero oggetto.
Riporto un po' di codice, così capite meglio:
- products.aspx , div relativo alla tabella:
<div class="products_table">
<asp:GridView AutoGenerateColumns="false" ID="GridView1" runat="server" DataSourceID="AccessDataSource1"
OnRowDataBound="GVRowDB">
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Label ID="lblFAM" runat="server" class="desc_fam" Text='<%#Eval("DESC_FAM") %>'></asp:Label>
<table>
<tr>
<td class="desc_sfam"><asp:Label ID="lblDescSFam" runat="server" Text='<%#Eval("DESC_SFAM") %>'></asp:Label></td>
<td class="expand">[+]</td>
<td class="p_name"><asp:Label ID="lblName" runat="server" Text='<%#Eval("P_NAME") %>'></asp:Label>
<table class="child">
<td class="p_desc">
<asp:Label ID="lblDesc" runat="server" Text='<%#Eval("P_DESC") %>'></asp:Label>
<br />
<a href="products/<%#eval("P_Pdf") %>" target="_blank"><img class="prod_icone" src="images/data_sheet_icon.png" alt="alternative text" title="SCHEDA TECNICA / DATA SHEET" ></a>
<a href="products/<%#eval("P_PdfMSDS") %>" target="_blank"><img class="prod_icone" src="images/msds_icon.png" alt="alternative text" title="SCHEDA DI SICUREZZA / MATERIAL SAFETY DATA SHEET" ></a>
</td>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:AccessDataSource ID="AccessDatasource1" runat="server" SelectCommand="SELECT products.FAM, products.SFAM, products.P_MARCA, products.P_NAME, products.COLNR, products.RIGANR, products.P_DESC, T_SFAM.DESC_SFAM, products.P_Pdf, products.P_PdfMSDS, T_FAM.DESC_FAM FROM (products LEFT JOIN T_SFAM ON products.SFAM = T_SFAM.ID_SFAM) LEFT JOIN T_FAM ON products.FAM = T_FAM.ID_FAM WHERE (((products.COLNR)=20) AND ((products.PAGINANR)=[@pageno]) AND ((products.anno)=2015)) ORDER BY products.COLNR, products.RIGANR" CancelSelectOnNullParameter="false"
datafile="percorso\database.mdb">
<SelectParameters>
<asp:QueryStringParameter Name="pageno" DbType = "string" Direction = "Input" QueryStringField="pageno" DefaultValue="" ConvertEmptyStringToNull="True" />
<asp:QueryStringParameter Name="tipologia" DbType = "string" Direction = "Input" QueryStringField="tipologia" DefaultValue="" ConvertEmptyStringToNull="True" />
</SelectParameters>
</asp:AccessDataSource>
</div>
- css class "desc_sfam":
.desc_sfam {
width:80px;
vertical-align: top;
color: #FFFFFF;
border-style: none none dotted dotted;
- products.aspx.vb :
Partial Class products_grid
Inherits System.Web.UI.Page
Protected Sub GVRowDB(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim titleLabel As Label = e.Row.FindControl("lblTitle")
Dim famlabel As Label = e.Row.FindControl("lblFAM")
Dim colnrlabel As Label = e.Row.FindControl("lblCol")
Dim descsfamlabel As Label = e.Row.FindControl("lblDescSFam")
Dim strval As String = CType(titleLabel, Label).Text
Dim strfamval As String = CType(famlabel, Label).Text
Dim strcolnrval As string = CType(colnrlabel, Label).Text
Dim strdescsfamval As String = CType(descsfamlabel, Label).Text
Dim title As String = ViewState("title")
Dim titlefam As String = ViewState("titlefam")
Dim titlecolnr As String = ViewState("titlecolnr")
Dim titledescsfam As String = ViewState("titledescsfam")
If title = strval Then
titleLabel.Visible = False
titleLabel.Text = String.Empty
Else
title = strval
ViewState("title") = title
titleLabel.Visible = True
titleLabel.Text = "<b>" & title & "</b><br>"
End If
If titlefam = strfamval Then
famlabel.Visible = false
famlabel.Text = String.Empty
Else
titlefam = strfamval
ViewState("titlefam") = titlefam
famlabel.Visible = True
famlabel.Text = "<b>" & titlefam & "</b><br>"
End If
If titledescsfam = strdescsfamval Then
descsfamlabel.Visible = false
descsfamlabel.Text = String.Empty
e.Row.CssClass += "prova"
Else
titledescsfam = strdescsfamval
ViewState("titledescsfam") = titledescsfam
descsfamlabel.Visible = True
descsfamlabel.Text = "<b>" & titledescsfam & "</b><br>"
End If
End If
End Sub
End Class
- css class "prova" :
.prova {
color: #fff;
background-color: #000;
border-style: none none dotted dotted;
border-color: #4cff00;
}
in realtà il border-color: #4cff00; è usato come test per capire su quale parte della tabella sto agendo, ed in effetti mi dimostra che non riesco a raggiungere il campo che serve a me.
Per capire meglio, allego anche tre screenshots (sperando si possano inserire immagini nel post, ho messo sia i BB code che i linked BBCode):
- questo è il risultato attuale (senza modifica di css class)
[img]http://i.imgur.com/mLROB0z.jpg[/img]
[url=http://imgur.com/mLROB0z][img]http://i.imgur.com/mLROB0z.jpg[/img][/url]
- questo è il risultato desiderato
[img]http://i.imgur.com/cWGvJpB.jpg[/img]
[url=http://imgur.com/cWGvJpB][img]http://i.imgur.com/cWGvJpB.jpg[/img][/url]
- questo è il risultato che si raggiunge applicando il cambio css class nel codebehind
[img]http://i.imgur.com/eM76aQx.jpg[/img]
[url=http://imgur.com/eM76aQx][img]http://i.imgur.com/eM76aQx.jpg[/img][/url]
In definitiva, vorrei capire se dal codice vb riesco a fare riferimento al campo DESC_SFAM oppure se al massimo posso arrivare alla cella (0) completa; nel caso della seconda ipotesi, posso porre rimedio in qualche modo, oppure ho proprio sbagliato la logica di recupero dati e di binding alla tabella?
Scusate la lungaggine del post
Ringrazio già da ora tutti quelli che mi risponderanno.
Saluti
Stefano