gridview问题,请大家帮忙! 在一个页面下,怎样选中gridview中的记录,把这条记录传到文本框中?我是新手,请说的详细些,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你点提示:下面是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; } 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; } } 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(); } VS2008 在添加数据库时,事件日志文件已满,烦 【求助】网站login的问题 子窗体的问题..! window.opener的意思是??? 当访问一个网页的时候,浏览器是边读边显示HTML ,还是读完在显示??如何编程中控制这两种方式?? ajaxpro 问题 请熟悉这的高手指教 路过帮顶 急死人了 在存储过程中,sql语句的拼接问题 能不能在VS2003创建ASP页面?或者asp的web项目? C# 报表控件 高分请教高人!!!回复帖子的问题。 根据条件动态从数据库取数据生成treeveiw? 主页放在网站根目录下的web文件下的问题.
<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;
}
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;
}
}
--------------------------------------------
<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();
}