Asp.net 需要gridview行onrowdeleting的值

Asp.net 需要gridview行onrowdeleting的值,asp.net,gridview,Asp.net,Gridview,我无法得到这个值。我得到的是一个空白值或videoName=“”。如何获取videoName的值?在rowdeleting事件中,我使用Rows(e.Index).Cells(2).Text来获取值,但它是空的。有没有其他方法来获取字段“videoname” 受保护的子GridView1\u行删除(发件人作为对象,e作为GridViewDeleteEventArgs) Dim videoName为String=gridview1.Rows(e.RowIndex).单元格(2).文本 Dim va

我无法得到这个值。我得到的是一个空白值或videoName=“”。如何获取videoName的值?在rowdeleting事件中,我使用Rows(e.Index).Cells(2).Text来获取值,但它是空的。有没有其他方法来获取字段“videoname”

受保护的子GridView1\u行删除(发件人作为对象,e作为GridViewDeleteEventArgs)
Dim videoName为String=gridview1.Rows(e.RowIndex).单元格(2).文本
Dim val作为字符串=videoName
如果File.Exists(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)+“\contents\published”+videoName),则
File.Delete(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)+“\contents\published”+videoName)
如果结束
端接头
删除


当您将来从gridview添加或删除列时,这很容易出错。您的代码将再次失败。我建议您在MovieName字段的模板字段中使用标签&使用
FindControl
查找标签。 Aspx

已更新
我发现在代码中,movieName
Visible
属性设置为
false
。这将阻止它在页面上呈现。您可以将值存储在
数据键中,也可以删除visible=false以获取所需的值。

我这样做了,但仍然没有得到任何值:Dim lblMovieName As Label=Gridview1.Rows(e.RowIndex).FindControl(“VideoName”),Label Dim val As String=lblMovieName.Text。它表示对象引用未设置为对象的实例。在行中,“Dim val as String=lblMovieName。Text@mlg74您是否在gridview中创建了带有label控件的模板字段?噢!label lblMovieName=gvCustomer.Rows[e.RowIndex].FindControl(“YourLableControl”)作为标签;需要标签的id。我使用的是数据库名称。因此它是“FindControl”(“lblMovieName”),而不是findcontrol(“videoName”)。谢谢,它可以工作!
Protected Sub GridView1_RowDeleting(sender As Object, e As GridViewDeleteEventArgs)


    Dim videoName As String = gridview1.Rows(e.RowIndex).Cells(2).Text
    Dim val As String = videoName
    If File.Exists(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "\contents\published" + videoName) Then
        File.Delete(HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath) + "\contents\published" + videoName)
    End If
End Sub

<asp:GridView id="GridView1" runat="server" Width="680px" GridLines="None" DataSourceID="SqlDataSource2" DataKeyNames="id" CellSpacing="1" CellPadding="3" BorderWidth="2px" BorderStyle="Ridge" BorderColor="White" AutoGenerateColumns="False"
               AllowPaging="True" AllowSorting="True" EmptyDataText="No Record Found" OnRowDeleting="GridView1_RowDeleting" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="9" >
                <Columns>
                    <asp:BoundField HeaderText="Id" DataField="Id" ReadOnly="true" visible="false" />
                    <asp:BoundField HeaderText="CustomerID" DataField="CustomerID" ReadOnly="true" visible="false"/>
<asp:BoundField HeaderText="VideoName" DataField="VideoName" ReadOnly="true" visible="false"/>
                    <asp:TemplateField>
                        <HeaderStyle Width="5%" />
                        <ItemStyle Width="5%" />  
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" Runat="server" OnClientClick="return confirm('Are you sure you want to delete this video?');"
                                CommandName="Delete">Delete</asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>              
                    <asp:TemplateField HeaderText="Clip" SortExpression="ThumbName">  
                        <HeaderStyle Width="5%" />
                        <ItemStyle Width="5%" />                          
                        <ItemTemplate>                                    
                            <div style="margin:2px; width:133px; background-color:rgb(68,68,68); -moz-box-shadow: 5px 5px 5px rgba(68,68,68,0.6); -webkit-box-shadow:5px 5px 5px rgba(68,68,68,0.6);box-shadow:5px 5px 5px rgba(68,68,68,0.6); zoom: 1;">
                                <asp:hyperlink id="link" NavigateUrl='<%# Eval("VideoName", "~/Test/playVideos2.aspx?FileName={0}&Thumb=" + Eval("ThumbName") + "&Duration=" + Eval("Duration"))%>' runat="server">
                                    <asp:image id="img" ImageUrl='<%# String.Format("~/contents/thumbs/{0}",Eval("ThumbName"))%>' width="130" height="80" runat="server" />
                                </asp:hyperlink>  
                                <asp:Label ID="lblMovieName" Text='<%#Bind("VideoName") %>' runat="server"></asp:Label>                                          
                            </div>                                                     
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Date">
                        <HeaderStyle Width="15%" />
                        <ItemStyle Width="15%" />  
                        <ItemTemplate>
                           <asp:Label ID="date" runat="server" Text='<%# Bind("DateCreated") %>'></asp:Label><br />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderStyle Width="75%" />
                        <ItemStyle Width="75%" />  
                        <ItemTemplate>

                        </ItemTemplate>
                    </asp:TemplateField>

                </Columns>
                <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            </asp:GridView> 
<asp:TemplateField HeaderText="Movie Name" >
            <ItemTemplate>
                <asp:Label ID="lblMovieName" Text='<%#Bind("MovieName") %>' runat="server"></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
 protected void gvCustomer_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblMovieName = gvCustomer.Rows[e.RowIndex].FindControl("yourLableControlName") as Label;
        // Perform your delete
    }