在一个页面下,怎样选中gridview中的记录,把这条记录传到文本框中?我是新手,请说的详细些,谢谢!

解决方案 »

  1.   

    给你点提示:下面是repeater,但是方法都一样。你看看“修改”的链接就知道了。<asp:Repeater ID="rtAlbum"  runat="server">
                                <HeaderTemplate>
                                <tr class="webpageManageListTitle">
                                <td><input type="checkbox" name="allcheckbox" value="1" onclick="cball( );" /></td><td align="center"  >名称</td><td  >是否私有</td><td align="center" >创建时间</td><td  >修改</td></tr>
                                </HeaderTemplate>
                                <ItemTemplate>
                                <tr>
                                 <td><input type="checkbox" name="cbAlbumId" value="<%#DataBinder.Eval(Container.DataItem,"wppaguid")%>" /></td>
                                 <td align="left" ><%#DataBinder.Eval(Container.DataItem,"wppatitle")%></td>
                                 <td><%#DataBinder.Eval(Container.DataItem,"wppaislock").ToString()=="True"?"锁":"不锁"%></td>
                                 <td><%#DateTime.Parse(DataBinder.Eval(Container.DataItem, "wppacreatedate").ToString()).ToString("yyyy-MM-dd")%></td>
                                 <td><a href="javascript:modify('<%#DataBinder.Eval(Container.DataItem,"wppaguid")%>','<%#DataBinder.Eval(Container.DataItem,"wppatitle")%>','<%#DataBinder.Eval(Container.DataItem,"wppaintro")%>','<%#DataBinder.Eval(Container.DataItem,"wppaislock")%>','<%#DataBinder.Eval(Container.DataItem,"wppapassword")%>');">修改</a></td>
                                 </tr>
                                </ItemTemplate>
                    </asp:Repeater>
     function modify(guid,name,des,islock,password)
            {
     
                document.getElementById("hGuid").value = guid;
                document.getElementById("textName").value = name;
                document.getElementById("textDescription").value = des;
                
                var myObj=document.getElementsByName("radioislock"); 
                    for(i=0;i<myObj.length;i++){ 
                    if(myObj[i].value==islock)
                         myObj[i].checked = true;
                    };                 if(islock=='False')
                        document.getElementById("trpass").style.display = "none";
                    else
                        document.getElementById("trpass").style.display = "";
                document.getElementsByName("radioislock").value = islock;
                document.getElementById("textpassword").value = password;
     
            }
      

  2.   

    GridView编辑时获取编辑框中的值
    string quantity = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text;  protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "check")
            {
                string index= e.CommandArgument.ToString();
                GridViewRow row = GridView1.Rows[index];
                string id = row.Cells[1].Text;
            }
        }
      

  3.   

    HTML: 先创建一个gridview 然后在编辑列中添加选择列,绑定数据你就自己写吧
    --------------------------------------------
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                Style="position: relative" AllowPaging="True" AllowSorting="True" DataKeyNames="au_id" ForeColor="#333333" GridLines="None" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting" Width="701px" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand">
                <FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
                <Columns>
    ....
    <asp:CommandField HeaderText="选择" ShowSelectButton="True" />
    </Columns>
     </asp:GridView>C#:
    ----------------------------------------------------
    //选择列事件
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString());
            //有了主键值,写SQL语句查询数据库就行了
            string sql = "select * from table where uid = '"+ id +"'";
            SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
            SqlCommand com = new SqlCommand(sql, con);
            con.Open();
            SqlDataReader dr = com.ExecuteReader();        while (dr.Read())
            {
                Text1.Text = dr["username"].ToString();
                Text2.Text = dr["..."].ToString();
                ...
            }
            dr.Close();
            con.Close();
        }