首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

点击gridview时怎么获取单个cell的值

2012-04-15 
点击gridview时如何获取单个cell的值VB.NET codeProtected Sub gridview1_rowdatabound(ByVal sender As O

点击gridview时如何获取单个cell的值

VB.NET code
Protected Sub gridview1_rowdatabound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound              Dim count As Integer = gridview1.rows.count            For i As Integer = 0 To count - 1            session("course") = gridview1.datakeys(i).value.tostring()             response.write(session("course"))‘这里只能获取所有cell的值,怎样点击一次就获取一个gridview1.datakeys(i)的值?        Next    End Sub


[解决办法]
如果想在客户端取得:

<script type="text/javascript">
function OnSuccess(result)
{
document.getElementById('<%= HiddenX.ClientID %>').value = result;
}

</script>

<asp:TemplateField HeaderText="我爱你">
<ItemTemplate>
<asp:Button runat="server" ID="Btn" Text="噢耶~" />
</ItemTemplate>
</asp:TemplateField>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btn = (Button)e.Row.FindControl("Btn");

btn.OnClientClick = "OnSuccess('" + GridView1.DataKeys[e.Row.RowIndex].Value.ToString() + "');return false;";
}
 }
[解决办法]
绑定前
 GridView2.DataKeyNames = New String() {"classnum"}

然后
GridView2.DataKeys(GridView2.SelectedIndex).Value

热点排行