尝试使用vb.net在asp.net中获取gridview的当前单元格值

时间:2022-10-24 13:54:42
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

but strautoid always contains "" .....What to do

但是strautoid总是包含“”.....怎么办

html of gridview

<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> 

2 个解决方案

#1


1  

I haven't checked this exactly, but you need something like:

我没有仔细检查过,但你需要这样的东西:

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

As i say, haven't checked exactly but the key to getting this correct is in the FindControl method, i hope that helps.

正如我所说,没有完全检查,但获得这个正确的关键是在FindControl方法,我希望有所帮助。

#2


1  

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;

#1


1  

I haven't checked this exactly, but you need something like:

我没有仔细检查过,但你需要这样的东西:

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

As i say, haven't checked exactly but the key to getting this correct is in the FindControl method, i hope that helps.

正如我所说,没有完全检查,但获得这个正确的关键是在FindControl方法,我希望有所帮助。

#2


1  

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;