本文介绍了在asp.net中显示选定的gridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Gridview中如下
In Gridview as follows
Subject coursedate Candidates Checkbox
English 12 May 14 10 Checkbox1
Tamil 13 May 14 20 Checkbox2
当我点击Gridview中的复选框时,我想在文本框中显示所选的复选框gridview行。
i有一个文本框如下;
在文本框中我想要输出如下
When i click the checkbox in Gridview i want to display the selected checkbox gridview row in textbox.
i have one textbox as follows;
In textbox i want output as follows
English 12 May 14 10 Tamil 13 May 14 20 (Retrive from the gridview)
我怎样才能在asp.net中使用c#。
for that how can i do in asp.net using c#.
推荐答案
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" oncheckedchanged="CheckBox1_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TextBox ID="TextBox1" runat="server" Width="532px"></asp:TextBox>
代码
code behind
using System;
using System.Web.UI.WebControls;
using System.Data;
public partial class Default14 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == true)
return;
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("Student ID");
dtTemp.Columns.Add("First Name");
dtTemp.Columns.Add("Last Name");
dtTemp.Rows.Add("1", "Peter", "Leow");
dtTemp.Rows.Add("2", "James", "Song");
dtTemp.Rows.Add("3", "Mick", "Sam");
dtTemp.Rows.Add("4", "MAry", "Cool");
GridView1.DataSource = dtTemp;
GridView1.DataBind();
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
TextBox1.Text = "";
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox chkBox = (CheckBox)row.FindControl("CheckBox1");
if (chkBox != null && chkBox.Checked)
{
TextBox1.Text += " " + row.Cells[1].Text.ToString() + " " + row.Cells[2].Text.ToString() + " " + row.Cells[3].Text.ToString();
}
}
}
}
这篇关于在asp.net中显示选定的gridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!