开发者

problem with RowCommand in GridView

have this weird problem with the first click of a row item in a gridview where it doesnt fire. Im loading up a user control dynamically into a placeholder. After the first click fails, subsequent clicks are fine, and the RowCommand event fires.

Any suggestions appreciated

    protected void Page_Load(object sender, EventArgs e)
    {
        this.PreRender += new EventHandler(Group_PreRender);
        this.Init +=new EventHandler(Group_Init);
        AttachEvents();

        if (Page.IsPostBack)
        {
            GetData();

        }
        else
        {
            gvName.DataBind();
        }

    }


    private void AttachEvents()
    {
        gvName.RowCommand += new GridViewCommandEventHandler(gv开发者_StackOverflow社区Name_RowCommand);
    }
    protected void gvName_RowCommand(object sender, GridViewCommandEventArgs e)
    {
             //code here
    }

also tried adding the event in the markup

       <asp:Button ID="btnDisable" runat="server" CommandArgument="<% # Container.DataItemIndex %>" Visible="<%# ((EducateMe.BaseTypes.AbstractLink)Container.DataItem).IsActive == true %>" CommandName="Disable" ToolTip="Disable" Text="Apply" />

Update: This has been solved here ItemCommand not firing on first click in Repeater or GridView


public static class Find_Feature
{   
#region Export 
    public static void Add_Event_To_Button(Button btn, int Index, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Find_Window('" + Index + "','" + Primary_Key_Text_Field + "')";
    }

    public static void Add_Event_To_Button(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Search_Invoice_Form('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Button(Button btn, string Primary_Key_Text_Field, int Index)
    {
        btn.OnClientClick = "return Load_Search_Commercial_Invoice_Form('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Button_Post_Shipment(Button btn, string Primary_Key_Text_Field, int Index)
    {
        btn.OnClientClick = "return Load_Search_Commercial_Invoice__Post_Shipment_Form('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Print_Button(Button btn, Panel print)
    {
        btn.OnClientClick = "return Print('" + print.ClientID  + "');";
    }
    public static void Add_Event_To_Print_Button_ForIE(Button btn, Panel print)
    {
        btn.OnClientClick = "return PrintIE('" + print.ClientID + "');";
    }
    public static void Add_Event_To_Button_Advance(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Search_Pre_Advanced_Master('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Button_General_Packing_List_Combine(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Search_Packing_List('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Button_Other_Packing_List_Combine(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Search_Packing_List_Other('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Find_Company(Button btn, string Primary_Key_Text_Field, int Index)
    {
        btn.OnClientClick = "return Load_Company_List_Form('" + Primary_Key_Text_Field + "');";
    }

#endregion
#region Import

    public static void Add_Event_To_Button_Import(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Import_Search_Invoice_No('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Button_Import_commercial(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Import_Search_Commercial_Invoice_Form('" + Primary_Key_Text_Field + "');";
    }
    public static void Add_Event_To_Button_Import_commercial_PostShipment(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Import_Search_Commercial_Invoice_For_PostShipment('" + Primary_Key_Text_Field + "');";
    }
    //public static void Add_Event_To_Button_Import_Commercial_Invoice(Button btn, string Primary_Key_Text_Field)
    //{
    //    btn.OnClientClick = "return Load_imp_Search_Commercial_Invoice_No('" + Primary_Key_Text_Field + "');";
    //}
    //public static void Add_Event_To_Button_Import_Commercial_Invoice(Button btn, string Primary_Key_Text_Field)
    //{
    //    btn.OnClientClick = "return Load_imp_Search_Commercial_Invoice_No('" + Primary_Key_Text_Field + "');";
    //}

    public static void Add_Event_To_Button_Import_Commercial_Invoice(Button btn, string Primary_Key_Text_Field)
    {
        btn.OnClientClick = "return Load_Import_Search_Commercial_Invoice_Form('" + Primary_Key_Text_Field + "');";
    }
#endregion  
#region Textbox Events
    public static void Add_Event_To_TextBox(TextBox txt, int Index, string Primary_Key_Text_Field, string Next_To_Focus_Control)
    {
        txt.Attributes.Add("onfocus", "return Load_Search_Form('" + Index + "','" + Primary_Key_Text_Field + "','"
            + Next_To_Focus_Control + "')");
    }
    public static void Add_Event_To_TextBox(string tablename, TextBox txt, string Primary_Key_Text_Field, string Next_To_Focus_Control, string ID_Column, string Display_Field1, string Display_Field2, string ConditionField, string Opr, string value_field)
    {
        txt.Attributes.Add("onfocus", "return Load_Search_Form_byEmployee('" + tablename + "','" + Primary_Key_Text_Field + "','" + Next_To_Focus_Control +
            "','" + ID_Column + "','" + Display_Field1 + "','" + Display_Field2 + "','" + ConditionField + "','" + Opr + "','" + value_field + "')");
    }
 public static void Add_Event_To_Button(string tablename, Button btn, string Primary_Key_Text_Field, string ID_Column, string Display_Field1, string Display_Field2, string ConditionField, string Opr, string value_field)
    {
        btn.OnClientClick = "return Load_Search_Find_byEmployee('" + tablename + "','" + Primary_Key_Text_Field +
            "','" + ID_Column + "','" + Display_Field1 + "','" + Display_Field2 + "','" + ConditionField + "','" + Opr + "','" + value_field + "')";
    }
    #endregion
    public static void PostBack(Button btn)
    {
        btn.Attributes.Add("onclick", "__doPostBack();");
    }

    public static void Gratuity()
    {

    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜