簡體   English   中英

從gridview中的選定行獲取價值

[英]Getting value from selected row in gridview

我是一位新手VB程序員,試圖在gridview中檢索所選行的值。 尚未能夠完成。 我搜索了所有論壇,但沒有答案對我有用。 這是代碼的html部分:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" 
                ForeColor="#333333" GridLines="None" Width="1032px" 
                EnableModelValidation="True">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
        <asp:TemplateField HeaderText="Date" >
            <ItemTemplate>
                <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" onclick ="LinkButton1_Click"
                CommandName="DrillTP" Text='<%#Eval("transit_date")%>'> </asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
            <asp:BoundField DataField="transit_date" HeaderText="Date"  Visible="false" >

            <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
             <asp:BoundField DataField="day_type" HeaderText="DayType" >

            <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="current_route_id" HeaderText="Line" >

            <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
                            <asp:BoundField DataField="bs_lname" HeaderText="Location" >

            <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>

        </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

    </asp:GridView>

在Visual Basic中,我試圖捕獲選定的日期並將該信息放置在標簽中,但還不能。 有什么建議么? 我有這個:

Protected Sub LinkButton1_Click(sender As Object, e As EventArgs) '(sender As Object, e As DataGridCommandEventArgs)
            Label1.Text = GridView1.SelectedRow.DataItem

End Sub

顯然,我缺少了一些東西,感謝您的幫助。 另外,請告訴我是否可以更有效地發布此問題。 謝謝!!

您需要使用屬性Value,並且可能使用ToString方法。

GridView1.SelectedRows(0).Value.ToString()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM