怎么获取选中的信息
<asp:GridView ID="GridViewResource" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataSourceID="SqlDataResourceID" BackColor="#FFCCFF" Height="80px" PageSize="5"
Width="681px">
<Columns>
<asp:TemplateField HeaderText="资源名称" SortExpression="资源名">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="noUnderLine" NavigateUrl="~/ResourceDetail.aspx"
Text='<%# Eval("资源名") %>' Visible="True"></asp:HyperLink>
</ItemTemplate>
<ItemStyle Height="60px" HorizontalAlign="Left" Width="350px" Wrap="True" />
</asp:TemplateField>
<asp:BoundField DataField="资源分" HeaderText="资源分" SortExpression="资源分">
<ControlStyle BorderWidth="60px" />
</asp:BoundField>
<asp:BoundField DataField="关注度" HeaderText="关注度" SortExpression="关注度" />
<asp:BoundField DataField="发帖人" HeaderText="发帖人" SortExpression="发帖人">
<ControlStyle Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="更新时间" HeaderText="更新时间" SortExpression="更新时间">
<ControlStyle Width="150px" />
</asp:BoundField>
</Columns>
</asp:GridView>
如图:当选中图中的 "C++ 开发工具.exe" 时,怎么获取它的字段信息???
这些信息都是来自后台数据库的.
谢谢啦 --------------------编程问答-------------------- 你代码里是这样的不:<a href="ddd.aspx?pid=<%# Eval("pid")%>">C++ 开发工具.exe</a>
这样可以把PID参数传到你想要得到的地方,然后通过PID。
select * from table where pid = 传过来的参数 就可以得到选中行的所有字估信息了 --------------------编程问答-------------------- 你把你的HyperLink换成
<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument="<%# Eval("名称") %>" CommandName="type">LinkButton</asp:LinkButton>
指定CommandArgument="<%# Eval("名称") % 数据库绑定的动态字段
指定CommandName="type" 类型
然后后台激发一个RowCommand方法。就可以了 --------------------编程问答--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[i].Attributes.Add("onclick", "row_click('" + e.Row.Cells[0].Text + "')");
}
在页面写一个JS function row_click(value) 将value给隐藏控件。 --------------------编程问答-------------------- 一般我遇到这种情况,
都不是用HyperLink
而是用LinkButton
在LinkButton的Click事件中:
LinkButton btn=sender as LinkButton;
GridViewRow row=btn.Parent.Parent as GridViewRow ;
string str1=row.Cells[1].Text;
string str2=row.Cells[2].Text;
string str3=row.Cells[3].Text;
string str4=row.Cells[4].Text;
//ps:代码手打
--------------------编程问答--------------------
up --------------------编程问答--------------------
不行,我要显示数据信息呢。。。
我是菜鸟来的,
希望详细点.... --------------------编程问答-------------------- 忘啦.......
超链
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" CssClass="noUnderLine" NavigateUrl="~/ResourceDetail.aspx"
Text='<%# Eval("资源名") %>' Visible="True"></asp:HyperLink>
</ItemTemplate>
要跳转到其他页面的 --------------------编程问答--------------------
在linkbutton的click事件中利用 response.redict()进行页面跳转 --------------------编程问答-------------------- 前台 <asp:LinkButton runat="server" ID="lbClick" Text="修改" CommandName="upd" CommandArgument='<%# Eval("id")%>'></asp:LinkButton>
后台
protected void GridViewResource_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName =="upd")
{
int id = e.CommandArgument;
Response.Redirect("index.aspx?pid="+id);
}
} --------------------编程问答-------------------- 晕啊.....
在GridView 加不了 OnLinkButton的事件啊...
手工加入出错....
vs 怎么弄可以自动生成啊.....错误码:
错误 7 “OnLinkButtonClick”方法没有采用“0”个参数的重载 E:\My Documents\Visual Studio 2008\WebSites\resourceManagement\Default.aspx 1 1 E:\...\resourceManagement\
错误 8 “ASP.default_aspx”不包含“GridViewResource_SelectedIndexChanged”的定义,并且找不到可接受类型为“ASP.default_aspx”的第一个参数的扩展方法“GridViewResource_SelectedIndexChanged”(是否缺少 using 指令或程序集引用?) E:\My Documents\Visual Studio 2008\WebSites\resourceManagement\Default.aspx 1 1 E:\...\resourceManagement\
--------------------编程问答--------------------
OH,,NO..
不是为GridView加OnLinkButton事件
而是为linkbutton添加onclick事件
加法和普通linkbutton添加onclick事件一样 --------------------编程问答-------------------- 绑定一个主键 --------------------编程问答--------------------
事件是有啦。。。。
在这个事件里 获取 点击的GridView 中的数据呢,然后再跳转...
关键是 的到数据 啊......
还没有搞好....
谁来救我啊 --------------------编程问答-------------------- 在linkbutton 的onclick事件中添加此代码:
LinkButton btn=sender as LinkButton;
GridViewRow row=btn.Parent.Parent as GridViewRow ;
string str1=row.Cells[1].Text;
string str2=row.Cells[2].Text;
string str3=row.Cells[3].Text;
string str4=row.Cells[4].Text;
得不到数据吗? --------------------编程问答-------------------- 我要的是 点击 的那个数据 啊...... --------------------编程问答-------------------- 你这个点击的时候不是跳到其他页面去的嘛,在url后加个id之类的,到时在跳转后的页面再根据这个参数来读取信息就行啦 --------------------编程问答-------------------- 收藏......... --------------------编程问答--------------------
可以给个实例吗????
谢谢啦...... --------------------编程问答--------------------
--------------------编程问答-------------------- 晕死
LinkButton btn=sender as LinkButton;
GridViewRow row=btn.Parent.Parent as GridViewRow ;
string str0=row.Cells[0].Text;//这个不就是你点击的“资源名称” 嘛!
string str1=row.Cells[1].Text;
string str2=row.Cells[2].Text;
string str3=row.Cells[3].Text;
string str4=row.Cells[4].Text;
这个本身就是个基础
给你个GridView72般绝技 慢慢学习
把你邮箱给我 --------------------编程问答--------------------
ekisstherain@163.com 或 772603981@qq.com
谢谢啦~~~~~~~~~~~~~~ --------------------编程问答-------------------- 终于弄好啦~~~~~~~
先谢谢各位。。。。。
前台代码:
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName='link'
CommandArgument='<%# Eval("资源ID") %>' Text='<%# Eval("资源名") %>'></asp:LinkButton>
后台代码:
if ( e.CommandName == "link" )
{
Response.Write( e.CommandArgument.ToString());
}
补充:.NET技术 , ASP.NET