我有一個Web應用程序,在VB/ASPX中,GridView在我的aspx文件中填充了一個SqlDataSource。就像這樣:GridView和隱藏域
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" SkinID="dataGrid" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField AccessibleHeaderText="id_session" HeaderText="id_session">
<EditItemTemplate>
<asp:TextBox ID="txt_id_session" runat="server" Text='<%# Bind("id_session") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lbl_id_session" runat="server" Text='<%# Bind("id_session") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Formation_2014ConnectionString %>"
SelectCommand="SELECT s.id_session, f.libelle_formation, s.date_debut_session, s.date_fin_session, COUNT(p.id_personne) AS Expr1 FROM Sessions AS s LEFT OUTER JOIN Participe AS p ON p.id_session = s.id_session AND p.actif = 1 RIGHT OUTER JOIN Formation AS f ON f.id_formation = s.id_formation WHERE (s.date_fin_session > GETDATE()) OR (s.date_fin_session < GETDATE()) OR (S.date_fin_session = GETDATE()) GROUP BY s.id_session, f.libelle_formation, s.date_debut_session, s.date_fin_session" >
</asp:SqlDataSource>
這件作品,在這之後我與這個代碼在我隱藏隱藏第一列,「id_session」:
Protected Sub OnRowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowCreated
GridView1.Columns(0).Visible = False
'e.Row.Cells(0).Visible = False 'This way delete my paging
(Requête)
End Sub
在這之後,我必須得到在我的VB代碼這個隱藏列的值,我嘗試不同的方式,但沒有什麼> <
Dim id_session = GridView1.SelectedRow.Cells(0).Controls(0).ToString 'Return System.Web.UI.Literalcontrol
Dim id_session = GridView1.SelectedRow.RowIndex 'Return number of line
對不起,我的英語,我是法國人!
檢查下面的解決方案,爲任何幫助只是讓我知道 – Developerzzz