解决方案 »

  1.   

    按钮设置命令后,在命令执行的事件中,通过Convert.ToInt32(e.CommandArgumentCo)获取行索引,这样你通过索引就可以访问到数据集中指定索引的row,就可以访问其中各个单元格了
      

  2.   

    按钮命令是什么..可以详细一点么   哪个事件..  我的按钮都是这个时间下判断的.
     
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            
            if (e.CommandName == "del")
            {
                ppm.DeletePaper(Convert.ToInt32(e.CommandArgument.ToString()));
                this.GridView1.DataSource = ppm.GetPapers();
                this.GridView1.DataBind();
            }
      

  3.   

    实现点击GridView控件某行修改该行模板包含控件的信息示例
    //GridView设置
     <asp:GridView ID="gvAdmin" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" Font-Size="9pt" Width="500px" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" Font-Bold="False" OnRowDataBound="gvAdmin_RowDataBound">
                                        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                        <Columns>
                                            <asp:BoundField HeaderText="管理员ID" DataField="ID" />
                                            <asp:BoundField HeaderText="用户名" DataField="UserName" />
                                            <asp:BoundField HeaderText="管理员性别" DataField="Sex" />
                                            <asp:BoundField HeaderText="QQ" DataField="QQ" />
                                            <asp:BoundField HeaderText="注册时间" DataField="RegTime" />
                                            <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="AdminInfo.aspx?ID={0}"
                                                HeaderText="修改信息" Text="修改信息" />
                                                                              </Columns>//codego.net/tags/11/1/
                                        <SelectedRowStyle BackColor="#C5BBAF" ForeColor="#333333" Font-Bold="True" />
                                        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
                                        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
                                        <AlternatingRowStyle BackColor="White" />
                                        <RowStyle BackColor="#E3EAEB" />
                                        <EditRowStyle BackColor="#7C6F57" />
                                    </asp:GridView>
    //根据ID号跳转修改页面显示该行修改信息
     <asp:TextBox ID="txtName" runat="server" BackColor="White" Width="115px"></asp:TextBox>//管理员名称
    <asp:TextBox ID="txtPwd" runat="server" BackColor="#E0E0E0" ReadOnly="True" Width="117px"></asp:TextBox>//显示密码
    <asp:TextBox ID="txtOKpwd" runat="server" Width="117px"></asp:TextBox>//修改密码
    <asp:DropDownList ID="ddlSex" runat="server">
                                        <asp:ListItem>男</asp:ListItem>
                                        <asp:ListItem>女</asp:ListItem>
                                    </asp:DropDownList>//显示性别设置
    <asp:TextBox ID="txtRealName" runat="server" Width="117px"></asp:TextBox>//显示真实姓名
     <asp:TextBox ID="txtBirthday" runat="server" Width="117px"></asp:TextBox>//显示生日
    员:<asp:DropDownList ID="DropDownList1" runat="server" Height="17px" Width="45px">
                                        <asp:ListItem Value="True">是</asp:ListItem>
                                        <asp:ListItem Value="False">否</asp:ListItem>
                                    </asp:DropDownList>//修改是否超级管理员
     <asp:Button ID="btnUpdate" runat="server" Font-Size="9pt" Text="修改" OnClick="btnUpdate_Click" />//修改事件按钮
    //cs页面加载显示修改信息内容
      protected void Page_Load(object sender, EventArgs e)
        {
           
    if (!IsPostBack)
    {
    try
    {
    SqlConnection mycon = new SqlConnection(ConfigurationManager.AppSettings["conStr"]);
    mycon.Open();
    DataSet mydataset = new DataSet();
    SqlDataAdapter mydataadapter = new SqlDataAdapter("select * from tb_Admin where id=" + Request["id"],mycon);
    mydataadapter.Fill(mydataset, "tb_Admin");
    DataRowView rowview = mydataset.Tables["tb_Admin"].DefaultView[0];
    this.txtName.Text = Convert.ToString(rowview["UserName"]);
    this.txtPwd.Text = Convert.ToString(rowview["PassWord"]);
    this.ddlSex.SelectedValue = Convert.ToString(rowview["Sex"]);
    this.txtRealName.Text = Convert.ToString(rowview["ReallyName"]); this.DropDownList1.SelectedValue = Convert.ToString(rowview["SuperAdmin"]);
    this.txtIP.Text = Convert.ToString(rowview["IP"]);
    mycon.Close();
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    }
        }
    //修改行信息数据
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
    try
    {
    SqlData da = new SqlData();
    string P_str_Com = "update tb_Admin set UserName='" + this.txtName.Text + "',PassWord='" + this.txtOKpwd.Text + "'"
    + ",Sex='" + this.ddlSex.SelectedValue + "',ReallyName='" + this.txtRealName.Text + "',SuperAdmin='" + this.DropDownList1.SelectedValue + "'"
    + " where ID='" + Request["ID"] + "'";
    bool add = da.ExceSQL(P_str_Com);
    if (add == true)
    {
    Response.Write("<script language=javascript>alert('修改信息成功!');location='AdminManage.aspx'</script>");
    }
    else
    {
    Response.Write("<script language=javascript>alert('修改信息失败!');location='javascript:history.go(-1)'</script>");
    }
    }
    catch (Exception ex)
    {
    Response.Write(ex.Message);
    }
    }