c# – 如何使用rowdeleting事件删除gridview中的行?

c# – 如何使用rowdeleting事件删除gridview中的行?,第1张

概述这是我的.cs代码: protected void Gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e){ Gridview1.DeleteRow(e.RowIndex); Gridview1.DataBind();} 这是标记, <asp:gridview ID="Gridview1" runat="server" 这是我的.cs代码:

protected voID GrIDvIEw1_RowDeleting(object sender,GrIDVIEwDeleteEventArgs e){ GrIDvIEw1.DeleteRow(e.RowIndex); GrIDvIEw1.DataBind();}

这是标记,

<asp:grIDvIEw ID="GrIDvIEw1" runat="server" ShowFooter="true"                                                 autoGenerateColumns="false" OnRowDeleting="GrIDvIEw1_RowDeleting">                    <Columns>                    <asp:BoundFIEld datafield="RowNumber" headerText="Row Number" />                    <asp:TemplateFIEld headerText="Column name">                        <ItemTemplate>                            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>                        </ItemTemplate>                    </asp:TemplateFIEld>                 <%-- <asp:TemplateFIEld headerText="header 2">                        <ItemTemplate>                            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>                        </ItemTemplate>                    </asp:TemplateFIEld>--%>                    <asp:TemplateFIEld headerText="Data Type">                        <ItemTemplate>                              <asp:DropDownList ID="ddldatatype" runat="server">                              <asp:ListItem>varchar</asp:ListItem>                              <asp:ListItem>int</asp:ListItem>                              <asp:ListItem>numeric</asp:ListItem>                              <asp:ListItem>uniqueIDentifIEr</asp:ListItem>                              <asp:ListItem>char</asp:ListItem>                              </asp:DropDownList>                        </ItemTemplate>                        <FooterStyle HorizontalAlign="Right" />                        <FooterTemplate>                        <asp:button ID="buttonAdd" runat="server" Text="Add New Row" OnClick="buttonAdd_Click"/>                         <asp:button ID="buttonDel" runat="server" Text="Delete Row" OnClick="buttonDel_Click" />                         <input type="hIDden" runat="server" value="0" ID="hIDdencount" />                        </FooterTemplate>                    </asp:TemplateFIEld>                    <asp:TemplateFIEld>                        <ItemTemplate>                            <asp:linkbutton ID="lnkdelete" runat="server" Commandname="Delete" >Delete</asp:linkbutton>                        </ItemTemplate>                    </asp:TemplateFIEld>                    </Columns>            </asp:grIDvIEw>

请认真我.我做了这么多..但仍然没有删除行…

protected voID GrIDvIEw1_RowDeleting(object sender,GrIDVIEwDeleteEventArgs e)         {             //GrIDvIEw1.DeleteRow((int)GrIDvIEw1.DataKeys[e.RowIndex].Value);             //GrIDvIEw1.DeleteRow(e.RowIndex);             //GrIDvIEw1.DataBind();             foreach(DaTarow dr in dt.Rows)             {                 dt.Rows.Remove(dr);                 dt.Rows[e.RowIndex].Delete();             }             GrIDvIEw1.DeleteRow(e.RowIndex);            // dt = (Datatable)GrIDvIEw1.DataSource;             GrIDvIEw1.DataSource = dt;             GrIDvIEw1.DataBind();       }
解决方法
protected voID GrIDVIEw1_RowDeleting(object sender,GrIDVIEwDeleteEventArgs e){    GrIDVIEwRow row = (GrIDVIEwRow)GrIDVIEw1.Rows[e.RowIndex];    sqlCommand cmd = new sqlCommand("Delete From usertable (username,age,birthPLace)");    GrIDVIEw1.DataBind();}
总结

以上是内存溢出为你收集整理的c# – 如何使用rowdeleting事件删除gridview中的行?全部内容,希望文章能够帮你解决c# – 如何使用rowdeleting事件删除gridview中的行?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1225937.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存