如何从网格视图重定向单击某一行的时候 [英] How can I redirect from a grid view when a row is clicked

查看:158
本文介绍了如何从网格视图重定向单击某一行的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网格视图,当点击它重定向页面和URL一起发送MSGID我有一个模板字段按钮,是否有可能做到这一点通过单击行,也就是说,在任何地方,如果我点击MSGID或标题现场那么它应该重定向到与行MSGID响应指标页。就像一个选择按钮,

 的MsgID标题操作

1第一个图像(这重定向)
2秒图像(这重定向)

在此表,如果在一行的任何点在用户点击1,则该页面应该重定向,它具有执行图像的同样的动作。我怎样才能做到这一点。



 < ASP:GridView控件ID =Grid_Messagetable=服务器边框宽度=5的网格线=无
的CssClass =gridTable的SelectedIndex =0
的DataKeyNames =的MsgIDShowHeaderWhenEmpty =真
OnRowDataBound =MyGrid_RowDataBound的AutoGenerateColumns =假AllowSorting =真
OnSorting =gridView_Sorting> <柱体和GT;

< ASP:BoundField的数据字段=的MsgID的HeaderText =的MsgID的SortExpression =的MsgID/>
< ASP:BoundField的数据字段=标题ItemStyle-WIDTH =35%的HeaderText =主题的SortExpression =标题/> < ASP:的TemplateField的HeaderText =操作ItemStyle-WIDTH =15%>
<&ItemTemplate中GT;
< ASP:ImageButton的ID =imgbtn_ViewDashBoard的ImageUrl =样式/图像/ icon_dashboard.png
启用=真WIDTH ==服务器一项PostBackUrl ='<%#的eval(的MsgID,ResponseMetric.aspx的MsgID = {0}?)%GT;'
文本='发送'工具提示=查看仪表盘>< / ASP:ImageButton的>
< / ItemTemplate中>
< / ASP:的TemplateField>

< /专栏>
< / ASP:GridView的>


解决方案

您可以使用的RowDataBound 事件附加一个click事件的行



标记:

  =重定向功能(){
window.location.hef =home.aspx;
}

< ASP:GridView控件ID =GridView1=服务器OnRowDataBound =GridView1_RowDataBound...>



代码隐藏:

 保护无效GridView1_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
e.Row.Attributes [的onclick] =重定向();
}


In my grid View I have a template field button when clicked it redirects the page and sends the msgid along with the url, Is it possible to do that by clicking anywhere in the row, i.e if i click on the msgid or title field then it should redirect to respond metric page with the row msgid. Just like a select button,

MsgID      Title       Actions

1          First        Image(Which redirects)
2          second       Image(Which redirects)

in this table if the user clicks on any spot in row 1 then the page should redirect, it has to perform the same action of Image. How can I do that

  <asp:GridView ID="Grid_Messagetable" runat="server" BorderWidth="5" GridLines="None"
                    CssClass="gridTable" SelectedIndex="0"
                     DataKeyNames="MsgID" ShowHeaderWhenEmpty="true"
                    OnRowDataBound="MyGrid_RowDataBound" AutoGenerateColumns="False" AllowSorting="true"
                    OnSorting="gridView_Sorting" >                                     <Columns>

                        <asp:BoundField DataField="MsgID" HeaderText="MsgID" SortExpression="MsgID" />
                        <asp:BoundField DataField="Title" ItemStyle-Width="35%" HeaderText="Subject" SortExpression="Title" />                                                          <asp:TemplateField HeaderText="Actions" ItemStyle-Width="15%">
       <ItemTemplate>
           <asp:ImageButton ID="imgbtn_ViewDashBoard"  ImageUrl="Styles/Images/icon_dashboard.png"
                                    Enabled="True" Width="" runat="server" PostBackUrl='<%# Eval("MsgID", "ResponseMetric.aspx?MsgID={0}") %>'
                                    Text='Send' ToolTip="View DashBoard"></asp:ImageButton>
                            </ItemTemplate>
                        </asp:TemplateField>

                    </Columns>
                </asp:GridView>

解决方案

You can use the RowDataBound event to attach a click event to the row.

Markup:

redirect = function(){
    window.location.hef = "home.aspx";
}

<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound" ...>

Code-behind:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Attributes["onclick"] = "redirect();"
}

这篇关于如何从网格视图重定向单击某一行的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆