簡體   English   中英

嘗試使用vb.net在asp.net中獲取gridview的當前單元格值

[英]Trying to get current cell value of gridview in asp.net using vb.net

Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
sqlqrystrng = "UPDATE temp_zone set zone_id = @zoneid, zone_name = @zonename WHERE auto_id = @autoid"
Dim strautoid As String = GridView1.Rows(e.RowIndex).Cells(1).Text()
End Sub

但是strautoid總是包含“”.....怎么辦

gridview的html

<asp:GridView ID="GridView1" runat="server" "AutoGenerateColumns="False" GridLines="None">   
     <RowStyle BackColor="#CCFFFF" ForeColor="#333333" />
     <Columns>
        <asp:TemplateField HeaderText="Auto Id">
           <ItemTemplate>
               <asp:Label ID="Label1" runat="server" Text='<%# Eval("auto_id") %>'>
               </asp:Label>
           </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Zone Id">
           <ItemTemplate>
               <asp:Label ID="Label2" runat="server" Text='<%# Eval("zone_id") %>'>
               </asp:Label>
           </ItemTemplate>
          <EditItemTemplate>
               <asp:TextBox ID="grdtxt_id" runat="server" Text='<%# Eval("zone_id") %>'>
               </asp:TextBox>
          </EditItemTemplate>
       </asp:TemplateField>
       <asp:CommandField HeaderText="Edition" ShowEditButton="True" CausesValidation="False" />
       <asp:CommandField HeaderText="Deletion" ShowDeleteButton="True" CausesValidation="False" />
    </Columns>
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
 </asp:GridView> 
You Have to Try this 

Dim strautoid As String = GridView1.Rows(e.RowIndex).Cells(1).Text()  instead of this ,try below

 TableCell cl = GridView1.Rows[e.RowIndex].Cells[1];

(Label) lbl=(Label).cl.FindControl("Your Label ID");

Dim strautoid As String=lbl.Text;

我沒有完全檢查過,但你需要這樣的東西:

Dim lblCell as label = GridView1.Rows(e.RowIndex).Cells(1).FindControl("labelID")
Dim strautoid As String = lblCell.Text

正如我所說,沒有完全檢查,但獲得這個正確的關鍵是在FindControl方法,我希望有所幫助。

暫無
暫無

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

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