GridView 一些操作

在ASP.NET里用C# 如何双击GridView 某一行的任意一个位置 ,打开一个对应的界面

protected void gvCustom_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
             //设置弹出窗体
            string CustomID= gvCustom.DataKeys[ e.Row.RowIndex][“CustomID“].ToString() ;
            e.Row.Attributes.Add(“ondblclick“, “javascript:window.showModalDialog(‘./CustomInfo.aspx?CustomID=“ + CustomID + “‘,window,‘scroll:no;status:no;center:yes;dialogHeight:480px;dialogWidth:700px;‘);“);
        }
   }

用鼠标选中一行之后点击删除就删除一行,不要Gridview自带的!

你的表肯定有个ID的主键值吧,你的gridview要设定一下DataKeyNames=“ID“这个属性值,接下的事件就好多了,写个OnRowDeleting=“PublicGridRowDeleting“事件就可以了。

其实你不需要radiobutton的,一个按钮就可以取到ID值来了,我把所有代码贴出你看下!


                        <asp:GridView ID=“GridLog“ runat=“server“ AutoGenerateColumns=“False“ CellPadding=“4“ DataKeyNames=“ID“
              BorderColor=“#333“ BorderStyle=“solid“ BorderWidth=“1“ OnRowDeleting=“PublicGridRowDeleting“
             GridLines=“None“ Width=“98%“ ForeColor=“#333333“>
                <FooterStyle BackColor=“#507CD1“ ForeColor=“White“ Font-Bold=“True“ />
                <Columns>
                    <asp:BoundField DataField=“ID“ HeaderText=“ID“  InsertVisible=“false“ ReadOnly=“True“
                        SortExpression=“ID“ >
                        <ItemStyle HorizontalAlign=“Center“ Width=“20px“ />
                    </asp:BoundField>

  <asp:TemplateField HeaderText=“删除“ ShowHeader=“False“>
                        <ItemStyle HorizontalAlign=“Center“ Width=“40px“ />
                        <ItemTemplate>
                            <asp:LinkButton ID=“LinkButton1“ runat=“server“ CausesValidation=“False“ CommandName=“Delete“ OnClientClick=“return confirm(‘您确认删除该规则‘);“ Text=“删除“></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <RowStyle BackColor=“#EFF3FB“ />
                <SelectedRowStyle BackColor=“#D1DDF1“ Font-Bold=“True“ ForeColor=“#333333“ />
                <PagerStyle BackColor=“#2461BF“ ForeColor=“White“ HorizontalAlign=“Center“ />
                <HeaderStyle BackColor=“#5A799C“  ForeColor=“White“ Height=“22px“ />
                <AlternatingRowStyle BackColor=“White“

为什么GridView只能编辑第一行?

写入如下代码:
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
GridView1.EditIndex = e.NewEditIndex;

                ((TextBox)GridView1.Rows[n].Cells[5].Controls[0]).ReadOnly = true;
}

点击第一行的时候可以编辑,但是点击其他行的时候,总是提示“指定的参数已超出有效值的范围”

请问这是为什么?应该如何解决?

GridView1.EditIndex = e.NewEditIndex;
 GridView1.DataBind();//此时使GridView1变成编辑状态
((TextBox)GridView1.Rows[e.NewEditIndex].FindControl(“TextBox1“)).ReadOnly = true; //此时要使编辑状态下的TEXTBOX的控件为不可用状态,最好是使用FindControl.当然使用Rows[n].Cells[5].Controls[0]也可以,但是这个就要注意Controls的索引对应的控件是否是你需要的TEXTBOX.

JS点击增加一行,点击删除一行的问题

下面代码可以增加一行,和删除表格指定行。
可以删除后继续增加却不行了。
请问是怎么回事?应如何修改一下让他可以继续增加呢?
谢谢。


<html> 
<%jj=date()&time()%>
<input name=“nn“ type=“hidden“ value=“<%=jj%>“>
<script type=“text/javascript“> 
var i=1; 
function insRow() 

var x=document.getElementById(‘myTable‘); 
//get the prefer row 
var beforeRow = x.rows(i-1); 
//get the prefer cell 
var beforeCell = beforeRow.cells(1); 
//set the cell‘s element to do nothing 
beforeCell.innerHTML=“<div align=center><input name=name“+(i-1)+“ type=text size=10 ></div>“; 
var oneRow = x.insertRow(); //get one of row 
//eight rows inserted 
var h1=oneRow .insertCell(0); 
var h2=oneRow .insertCell(1); 
var h3=oneRow .insertCell(2); 
var h4=oneRow .insertCell(3); 
var h5=oneRow .insertCell(4); 
var h6=oneRow .insertCell(5); 
var h7=oneRow .insertCell(6); 
var h8=oneRow .insertCell(7); 
h1.innerHTML=“<div align=center>“+(i+1)+“<input name=no type=‘hidden‘ value=“+(i+1)+“></div>“;
h2.innerHTML=“<div...

出错原因:
行索引的保存不当。

修改方法:
修改insRow()的第三行
var beforeRow = x.rows(i-1); 
-->
i = x.rows.length;
var beforeRow = x.rows(i-1);

原文地址:https://www.cnblogs.com/liufei88866/p/1442047.html