62,041
社区成员
发帖
与我相关
我的任务
分享
protected void gv_Person_SelectedIndexChanged(object sender, EventArgs e)
{
string name = gv_Person.SelectedRow.Cells[1].Text.ToString();
}
<asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False" onrowdatabound="GridView5_RowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%#DataBinder.Eval(Container,"DataItem.ID") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
protected void GridView5_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("style", "cursor:pointer");
e.Row.Attributes.Add("onclick", "document.getElementById('TextBox5').value=" + e.Row.RowIndex + "");
}
}
<script type="text/javascript">
function showRowId(obj, rowid) {
if (rowid != null) {
alert("当前是第"+rowid+"行!");
}
}
function showMsg(obj, msg) {
if (rowid != null) {
alert("当前行数据为:" + msg );
}
}
</script>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onclick","showMsg(this,'"+e.Row.Cells[0].Text+","+e.Row.Cells[1].Text+"')"); //获得主键
e.Row.Attributes.Add("onclick", "showRowId(this," + (e.Row.RowIndex + 1) + ")"); //显示当前第几行
}
}