本文介绍了如何在Gridview中获取所选行的HTML部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在第一列中有一个带复选框的gridview,我需要获取所选行的行部分的html.什么是这样做的好方法?
I've a gridview with checkbox in the first column, I need to get the html of the row portion of the selected row. what is a good way to do this?
以下部分逻辑是获取所选行html所必需的.
Below portion logic is required to get the selected row html.
foreach (GridViewRow row in GridView1.Rows)
{
if (!(row.FindControl("CheckBox1") as CheckBox).Checked)
{
//logic required here
}
}
推荐答案
您可以使用此代码段在GridView OnRowDataBound
事件中以HTML格式获取行.
You can use this snippet to get the row as HTML in the GridView OnRowDataBound
event.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox cb = e.Row.FindControl("CheckBox1") as CheckBox;
if (cb.Checked == true)
{
TableRow row = e.Row;
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
row.RenderControl(htw);
string rowContents = sw.ToString();
}
}
}
这篇关于如何在Gridview中获取所选行的HTML部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!