码迷,mamicode.com
首页 > 其他好文 > 详细

GRIDVIEW传值的两种方法

时间:2015-07-22 18:35:54      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:

第一种方法:在onselectedindexchanged中写事件

第二种方法:OnRowCommand事件

前端页面:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

?

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>

<div>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

DataKeyNames="no" onselectedindexchanged="GridView1_SelectedIndexChanged" OnRowCommand="TestGridView_RowCommand">

<Columns>

<asp:TemplateField>

<ItemTemplate>

<asp:LinkButton ID="TestLinkBtn" runat="server"

CommandName="Increase"

CommandArgument=‘<%#Eval("no")+","+Eval("MAC") %>‘

Text="CommandArgument示例"></asp:LinkButton>

</ItemTemplate>

</asp:TemplateField>

<asp:CommandField ShowSelectButton="True" />

<asp:BoundField DataField="no" HeaderText="no1" Visible="false"/>

<asp:BoundField DataField="MAC" HeaderText="name1"/>

<asp:BoundField DataField="DnsName" HeaderText="password1"/>

<asp:BoundField DataField="Domain" HeaderText="role1"/>

</Columns>

</asp:GridView>

</div>

</form>

</body>

</html>

?

后台页面:

第一种方法:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

{

this.Label1.Text = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString();

}

?

第二种方法:

protected void TestGridView_RowCommand(Object sender, GridViewCommandEventArgs e)

{

if(e.CommandName=="Increase")

{

//int index = Convert.ToInt32(e.CommandArgument);

//this.Label1.Text = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString();

this.Label1.Text = e.CommandArgument.ToString();

//GridViewRow row = GridView1.Rows[index];

Response.Write("<script language=javascript>alert(‘haahah‘)</script>");

}

}

GRIDVIEW传值的两种方法

标签:

原文地址:http://www.cnblogs.com/lovejunjuan/p/4667974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!