gridview中的按钮没有触发 [英] Button inside gridview not firing

查看:60
本文介绍了gridview中的按钮没有触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有gridview并且在gridview.onclick按钮内有一个按钮我需要导航到另一个页面。



行命令没有解雇



  protected   void  Page_Load( object  sender,EventArgs e)
{
if (!IsPostBack)
{
Bind_Evaluation();
}
}
受保护 void Bind_Evaluation()
{
gv_Evaluation.DataSource = ViewData [ MonthlyAward];
gv_Evaluation.DataBind();
}
受保护 void gv_Evaluation_RowCommand( object sender,GridViewCommandEventArgs e)
{
try
{

if (e.CommandName == 选择
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = gv_Evaluation.Rows [index];
int id = Convert.ToInt32(gv_Evaluation.DataKeys [index] .Value.ToString());
Response.Redirect( 〜/ Views / Evaluation / Submit_Evaluation.cshtml?index = + id);

}
Bind_Evaluation();
}
catch (例外情况)
{
throw Ex;
}
}





 <   asp:GridView     ID   =  gv_Evaluation   < span class =code-attribute> runat   =  server    EnableModelValidation   =     

< span class =code-attribute> AutoGenerateColumns = false OnRowCommand = gv_Evaluation_RowCommand DataKeyNames = Int_AssociateId >
< ; >



< asp:TemplateField < span class =code-attribute> HeaderText = Associate Id >
< ItemTemplate >
< asp:Label ID = Label1 runat = server

文字 =' <% #Bind( Int_AssociateId)%>' > < / asp:Label >
< / ItemTemplate > < / asp:TemplateField >
< asp:TemplateField < span class =code-attribute>
HeaderText = Associate Name >
< ItemTemplate >
< asp:标签 ID = Label1 runat = 服务器

文字 =' <% #Bind( Var_AssociateName)%>' > < / asp:标签 >
< / ItemTemplate > < / asp:TemplateField >

< asp:TemplateField HeaderText = 经理ID >
< ItemTemplate >
< asp:标签 ID = Label1 runat = server < span class =code-attribute>

< span class =code-attribute> 文本 =' <% #Bind( Int_ManagerId)%>' > < / asp:标签 >
< / ItemTemplate > < / asp:TemplateField >

< asp:TemplateField HeaderText = 经理名称 >
< ItemTemplate >
< asp:标签 ID = Label1 runat = server

文字 =' <% #Bind( Var_ManagerName)%>' > < / asp:标签 >
< / ItemTemplate > < / asp:TemplateField >

< asp:TemplateField HeaderText = 状态 >
< ItemTemplate >
< asp:标签 ID = Label1 runat = server

文本 =' <% #Bind( Var_Status)% >' > < / asp:标签 >
< / ItemTemplate > < / asp:TemplateField >

< < span class =code-leadattribute> asp:buttonfield buttontype = 按钮 commandname = 选择 headertext = text = 评估 / >

< ; /列 >
< / asp:GridView >

解决方案

而不是:

 <   asp:buttonfield     buttontype   = 按钮    commandname   = 选择    headertext   =     text   = 评估    xmlns:asp   = #unknown    /  >  



试试这个:

 <   asp:templatefield  >  
< itemtemplate < span class =code-keyword>>
< asp:button id = btn runat = server commandname = 选择 < span class =code-attribute> CausesValidation = false AutoPostBack = true text = 评估 > < / asp:button >
< / itemtemplate >
< / asp:templatefield >







--Amit


尝试使用temapte字段并使用锚标记并在内部使用Eval



 <   asp:TemplateField  >  
< HeaderTemplate >
< asp:标签 ID = lblIDLoc runat = server < span class =code-keyword>> 位置< / asp:标签 >
< / HeaderTemplate >
< Ite mTemplate >

< a href = 〜/ Views / Evaluation / Submit_Evaluation.cshtml?index = <% #Eval( Id%> > ClickTo Move < / a >
< / ItemTemplate >
< ItemStyle Horizo​​ntalAlign = 中心 / >
< / asp:TemplateField >


< asp:GridView ID =   grvView runat =   server AutoGenerateColumns =   false BorderWidth =   0 GridLines =  无 AllowPaging =   True宽度=   100% RowCommand =   grvView_RowCommand >  
< Columns>
< asp:TemplateField>
< HeaderTemplate>
< asp:按钮ID = grvbtnEdit CommandName = 选择 runat = server Text = 评估 > < / asp:按钮 >
< / HeaderTemplate >
< ItemTemplate>

// 您的代码

< / ItemTemplate >
< / asp:TemplateField >
< / >
< / asp:GridView >







  protected   void  grvView_RowCommand( object  sender,GridViewCommandEventArgs e)
{
if (e.CommandName == 选择
{
}
}


Hi,
I have gridview and have a button inside gridview.onclick of button i need to navigate to another page.

Row command is not firing

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind_Evaluation();
        }
    }
    protected void Bind_Evaluation()
    {
        gv_Evaluation.DataSource = ViewData["MonthlyAward"];
        gv_Evaluation.DataBind();
    }
protected void gv_Evaluation_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {

            if (e.CommandName == "Select")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow selectedRow = gv_Evaluation.Rows[index];
                int id = Convert.ToInt32(gv_Evaluation.DataKeys[index].Value.ToString());
                Response.Redirect("~/Views/Evaluation/Submit_Evaluation.cshtml?index=" + id);

            }
            Bind_Evaluation();
        }
        catch (Exception Ex)
        {
            throw Ex;
        }
    }



<asp:GridView ID="gv_Evaluation" runat="server" EnableModelValidation="True" 

    AutoGenerateColumns="false"  OnRowCommand="gv_Evaluation_RowCommand"  DataKeyNames="Int_AssociateId">
        <Columns>
         
             

            <asp:TemplateField HeaderText="Associate Id">
            <ItemTemplate>
        <asp:Label ID="Label1" runat="server" 

        Text='<%# Bind("Int_AssociateId") %>'></asp:Label>
    </ItemTemplate></asp:TemplateField>
            <asp:TemplateField HeaderText="Associate Name">
            <ItemTemplate>
        <asp:Label ID="Label1" runat="server" 

        Text='<%# Bind("Var_AssociateName") %>'></asp:Label>
    </ItemTemplate></asp:TemplateField>

        <asp:TemplateField HeaderText="Manager Id">
            <ItemTemplate>
        <asp:Label ID="Label1" runat="server" 

        Text='<%# Bind("Int_ManagerId") %>'></asp:Label>
    </ItemTemplate></asp:TemplateField>

        <asp:TemplateField HeaderText="Manager Name">
            <ItemTemplate>
        <asp:Label ID="Label1" runat="server" 

        Text='<%# Bind("Var_ManagerName") %>'></asp:Label>
    </ItemTemplate></asp:TemplateField>

        <asp:TemplateField HeaderText="Status">
            <ItemTemplate>
        <asp:Label ID="Label1" runat="server" 

        Text='<%# Bind("Var_Status") %>'></asp:Label>
    </ItemTemplate></asp:TemplateField>

   <asp:buttonfield buttontype="Button"  commandname="Select" headertext=""  text="Evaluate"/>  
     
        </Columns>
  </asp:GridView>

解决方案

Instead of:

<asp:buttonfield buttontype="Button" commandname="Select" headertext="" text="Evaluate" xmlns:asp="#unknown" />


Try this:

<asp:templatefield>
    <itemtemplate>
        <asp:button id="btn" runat="server" commandname="Select" CausesValidation="false" AutoPostBack="true" text="Evaluate"></asp:button>
    </itemtemplate>
</asp:templatefield>




--Amit


Try to use temapte field and use anchor tag and use Eval inside

<asp:TemplateField>
<HeaderTemplate>
  <asp:Label ID="lblIDLoc" runat="server">Location</asp:Label>
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    
<a href="~/Views/Evaluation/Submit_Evaluation.cshtml?index=<%# Eval("Id") %>">ClickTo Move</a>
                                                </ItemTemplate>
                                                <ItemStyle HorizontalAlign="Center" />
                                            </asp:TemplateField>


<asp:GridView ID="grvView" runat="server" AutoGenerateColumns="false" BorderWidth="0" GridLines="None" AllowPaging="True" Width="100%" RowCommand="grvView_RowCommand">
                        <Columns>
                            <asp:TemplateField>
                                <HeaderTemplate>
                                                                                    <asp:Button ID="grvbtnEdit" CommandName="Select" runat="server" Text="Evaluate" ></asp:Button>                                           
                                </HeaderTemplate>
                                <ItemTemplate>

                                     // YOUR CODE

                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>                                               
                    </asp:GridView>




protected void grvView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
            }
        }


这篇关于gridview中的按钮没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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