在GridView中选择按钮控件的索引 [英] Select Index Of Button Control In GridView

查看:96
本文介绍了在GridView中选择按钮控件的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 我有一个gridview
在我的网格视图中是以下控件:
标签,按钮,图像
我想要,当单击网格视图单元格的按钮时
转到webform2,并显示网格视图的该行(单元格)的更多信息
例如:单击按钮(text ="more info")并重定向到其他页面,并查看有关所单击的网格视图行的更多信息.
请给我一个C#代码

解决方案

您可以在Gridview中使用ASP:Template字段
与其他流程(如
不必调用Row_DataBound事件
为每个网格运行的
如果网格有1000行,则处理会变慢..

如何使用

 <   asp:templatefield     xmlns:asp   ="  <   asp:linkbutton    样式  ="     id   ="  文本  更多信息"  runat   ="     ="   <%#"  + Eval(" ).ToString()+ " );返回false;"%>"    / <  /asp:templatefield  > 




在网格之后,您可以添加一个javascript函数,即

 功能 gomore(id)
{
    窗口.位置 .href = "  viewmore.aspx?" + id;
}



试试吧.
如果有任何问题,请发表评论...

如果您的问题得到解决,则将其标记为解决方案.


它只是示例

 <   asp:GridView     ID   ="   ="span>    runat   =" 服务器"  AutoGenerateColumns   错误"  OnRowCommand   ="  > 
        <   > 
            <   asp:TemplateField     HeaderText   ="  <   ItemTemplate  > 
                    <   asp:Button     ID   ="   runat   服务器" 文本  单击以获取详细信息"  CommandName   ="     =' <%#Container.DataItemIndex %> '   / > 
                <  /ItemTemplate  > 
            <  /asp:TemplateField  > 
            <   asp:TemplateField     HeaderText   ="  <   ItemTemplate  > 
            <   asp:Label     ID   ="   runat   服务器" 文本  <% #Bind(" )%> '   / > 
                <  /ItemTemplate  > 
                <  /asp:TemplateField  > 

<  /列 > 
       <  /asp:GridView  >  




.cs文件中的代码应如下所示

 受保护的  void  gvUserdetails_RowCommand(对象发​​件人,GridViewCommandEventArgs e)
{
   如果(例如CommandName == " 跨度>)
   {
     int  index = Convert.ToInt32(e.CommandArgument);
    Response.Redirect(" );
   }
} 


hi i have a gridview
in my grid view is this controls:
label ,button,image
i want ,when click on button of a cell of grid view
go to webform2 ,and show more info of that row(cell) of grid view
example :click on button(text="more info") and redirect to other page and view more info about that row of grid view that clicked.
plz give me a c# code

解决方案

you can use ASP:Template Field in Gridview
Which works fast then other process like
Not Necessary to call Row_DataBound event
which run for each for of grid
if grid has 1000 of rows then process goes slow..

How to use

<asp:templatefield xmlns:asp="#unknown">
               <asp:linkbutton style="width:70px;" id="btnAct" text="More Info" runat="server" onclientclick="<%# "gomore(" + Eval("Id").ToString() + "); return false;" %>" />
               </asp:templatefield>




and after grid you can add a javascript function i.e.

function gomore(id)
{
    window.location.href="viewmore.aspx?"+id;
}



try it.
if any problem then comment...

if your problem got solved then mark it as solution ..


its just sample

<asp:GridView ID="gvUserdetails" runat="server" AutoGenerateColumns="False" OnRowCommand="gvUserdetails_RowCommand">
        <Columns>
            <asp:TemplateField HeaderText="DELETE">
                <ItemTemplate>
                    <asp:Button ID="btn1" runat="server" Text="Click for Details" CommandName="Show" CommandArgument='<%#Container.DataItemIndex %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="email">
                <ItemTemplate>
            <asp:Label ID="lblemail" runat="server" Text='<%#Bind("Email") %>' />
                </ItemTemplate>
                </asp:TemplateField>

</Columns>
       </asp:GridView>




and in .cs file code should be like this

protected void gvUserdetails_RowCommand(object sender, GridViewCommandEventArgs e)
{
   if (e.CommandName == "Delete")
   {
    int index=Convert.ToInt32(e.CommandArgument);
    Response.Redirect("required page url");
   }
}


这篇关于在GridView中选择按钮控件的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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