Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I have fileupload control, DropDown and GridviewControl

What is happening

I Upload a excel file which consist of n-sheets and all the sheet gets populated in dropdownlist perfectly and now I select any sheet name from the dropdown and all the rows and columns from excel gets populated in GridView

As this happens full post back when ever I select any value from dropdown. I wanted a partial postback using update panel. I am not able to achieve this

Problem: The value gets populated in dropwdown when ever i select any value or sheet name from he dropdown it is not getting displayed in Gridveiw. How can i fix this? when i remove the update panel it works fine.. Below is my code
C#
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">



    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
    <br />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="always">
 <ContentTemplate>
    <asp:DropDownList ID="ddlSheetName" runat="server" AutoPostBack="True" 
        onselectedindexchanged="ddlSheetName_SelectedIndexChanged">
    </asp:DropDownList>

     </ContentTemplate>
     <Triggers>
 <asp:AsyncPostBackTrigger ControlID="ddlSheetName" EventName="SelectedIndexChanged" />
 </Triggers>

 </asp:UpdatePanel>

    <br />
    <asp:Label ID="Label1" runat="server" Text="Has Header ?" />
    <asp:RadioButtonList ID="rbHDR" runat="server">
        <asp:ListItem Text="Yes" Value="Yes" Selected="True"></asp:ListItem>
        <asp:ListItem Text="No" Value="No"></asp:ListItem>
    </asp:RadioButtonList>
    <asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" Enabled="false"/>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="False" CssClass="table table-hover table-striped"
        AutoGenerateEditButton="false" CellPadding="4" ForeColor="Black" Height="110px"
        Style="margin-right: 0px" Width="1000px" BackColor="White" BorderColor="#CCCCCC"
        BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" OnRowEditing="GridView1_RowEditing"
        OnRowCancelingEdit="GridView1_RowCancelingEdit">
        <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
        <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F7F7F7" />
        <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
        <SortedDescendingCellStyle BackColor="#E5E5E5" />
        <SortedDescendingHeaderStyle BackColor="#242121" />
    </asp:GridView>
    
                
</asp:Content>
Posted

1 solution

Hi,

Issue is quite simple. your dropdowmlist is inside update panel and gridview is outside update panel. whenever dropdownlist triggers the postback, only the area inside update panel will get refreshed.

So, take the gridview inside update panel then it works fine.


hope it helps.
 
Share this answer
 
Comments
ShaHam11 21-Aug-14 2:52am    
Thank you so much it worked.fine for me. A quick question can i bring the file upload also inside the update panel as when i click the the upload button it does full postback. sorry for this silly question as i am very new to update panel Thank you
Karthik Harve 21-Aug-14 2:55am    
Ofcourse you can place it inside update panel. if the Gridview data is huge then, place two update panels, one with upload button and other with gridview and dropdownlist.
ShaHam11 21-Aug-14 5:48am    
I tried placing the fileupload control and upload button in update panel . It browse the file successfully but when i click on upload it doesn't upload and the sheet names are not populated in dropdown below is the code

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">




<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="always">

<contenttemplate>

<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
<br />
<asp:DropDownList ID="ddlSheetName" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlSheetName_SelectedIndexChanged">




<asp:Label ID="Label1" runat="server" Text="Has Header ?" />
<asp:RadioButtonList ID="rbHDR" runat="server">
<asp:ListItem Text="Yes" Value="Yes" Selected="True">
<asp:ListItem Text="No" Value="No">

<asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" Enabled="false"/>
<asp:GridView ID="GridView1" runat="server" AllowPaging="False" CssClass="table table-hover table-striped"
AutoGenerateEditButton="false" CellPadding="4" ForeColor="Black" Height="110px"
Style="margin-right: 0px" Width="1000px" BackColor="White" BorderColor="#CCCCCC"
BorderStyle="None" BorderWidth="1px" GridLines="Horizontal" OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit">
<footerstyle backcolor="#CCCC99" forecolor="Black">
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<sortedascendingcellstyle backcolor="#F7F7F7">
<sortedascendingheaderstyle backcolor="#4B4B4B">
<sorteddescendingcellstyle backcolor="#E5E5E5">
<sorteddescendingheaderstyle backcolor="#242121">


<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSheetName" EventName="SelectedIndexChanged" />

<asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />


</Triggers>



<br />
Karthik Harve 21-Aug-14 6:04am    
File upload control does not work with Asyncpostback, just change to PostBack Trigger.


<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlSheetName" EventName="SelectedIndexChanged" />
<asp:PostBackTrigger ControlID="btnUpload" />
</Triggers>
ShaHam11 21-Aug-14 6:12am    
So, I basically i can remove from the update panel. Because if i make it Only Postback trigger it refresh the whole page . Which does the same functionality when it is not placed in update panel

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900