复制代码 代码如下:
DataTable DT = new DataTable();
DT.Columns.Add("Name");
DT.Columns.Add("Sex");
DataRow dr = DT.NewRow();
dr[0] = "Kenny";
dr[1] = "男";
DT.Rows.Add(dr);
复制代码 代码如下:
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 && e.RowIndex != -1 && !dataGridView.Rows[e.RowIndex].IsNewRow)
{
String name = dataGridView.Rows[e.RowIndex].Cells["dataGridViewTextBoxColumn1"].Value.ToString();
MessageBox.Show(name);
}
}
复制代码 代码如下:
<asp:LinkButton runat="server" CommandName="Select" CommandArgument="<%#((GridViewRow)Container).RowIndex %>">查看截图</asp:LinkButton>
复制代码 代码如下:
protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
int index = Convert.ToInt32(e.CommandArgument); //行索引
GridViewRow row = this.GridView.Rows[index]; //获得GridViewRow的一行
Label label1 = (Label)row.FindControl("label1");
String name = label1.Text;
Response.Write(name);
}
}
新闻热点
疑难解答
图片精选