0 Replies - 1278 Views - Last Post: 18 May 2014 - 10:15 PM Rate Topic: -----

#1 zaidi87  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-May 14

Grid View Row Command Event Not Working

Posted 18 May 2014 - 10:15 PM

I am using GridView control for uploading files.I am using RowCommand Event for file uploading,
My scenario are like this
1: User login and comes to the page and upload file
2: User login, enter some data and save it(On Same Page where GridView is located),post back will occur and data will be shown in Grid.

The Upload functionality is working fine in scenario 1, however its not working after scenario 2, I put break point on Row Command Event its not hitting it incase of scenario 2
This is my Code
<asp:GridView ID="GVUsers" runat="server" OnRowDataBound="GVUsers_RowDataBound" OnRowCommand="GVUsers_RowCommand"
    OnRowDeleting="GVUsers_RowDeleting" AutoGenerateColumns="false" CssClass="table">
    <Columns>
            <asp:TemplateField HeaderText="Files" ItemStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:FileUpload ID="filedoc" runat="server" Width="98%" CssClass="filedoc" />
                    <asp:Button ID="btnuploadfiles" runat="server" CommandName="fileupd" Text="Upload"
                                                            CssClas="uploadbtn" />
                </ItemTemplate>
                 </asp:TemplateField>


    </Columns>
</asp:GridView>

protected void GVUsers_RowCommand(Object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "fileupd")
    {
            //Upload File
    }
}



This is how I am databinding the Grid in Page_Load Event
if(!Page.IsPostBack)
{
GVUsers.DataSource=dattable;
GVUsers.DataBind();
}



I also tried binding grid after the above condition,ie Binding Grid always,but no Luck
I tried assinging event handler from code behind,but same issue. On Save Button I am doing this after saving
protected void btnsave_Click(object sender, EventArgs e)
{
//Saving Data
GVUsers.DataSource=dattable;
GVUsers.DataBind();
}


as per I investigated, the problem is in btnsave_click,as I am rebinding the Grid,but if I use only GVUsers.DataBind() here,it will hide the GridView after saving.
I also have tried by disabling the ViewState of the Grid. How can I make RowCommand Working after post back or how can I re databind grid after save(ie Show newly added records after saving immediately,so RowCommand will still work)?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1