.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

GridView EditTemplate DropDownLists' Loads fire before SelectedIndexChanged events on AutoPostBack=

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :ASP.Net
My GridView allows EditTemplate but no DataSource in the aspx page. I set the DataSource & DataBind in code behind. My problem is with 2 of the 4 DropDownLists: they require AutoPostBack=true b/c the load of ddlDptmtGrid is dependant on the selection from ddlOrgGrid, and the load of ddlPosGrid is dependant on the selection from ddlDptmtGrid. The problem lies in that every postback calls each ddl's load & then the SelectedIndexChanged event, by this point the SelectedValue has been reset or wiped. And i can't use "if (!IsPostBack) { }" b/c the initial click of the lnkEditBtn is a postback & the DropDownLists don't even exist till in Edit Mode, so i need this initial load. But it appears on every postback all the controls in Edit mode are wiped & re-initialized, so it forces each DDL to be re-declared & re-loaded, but then the SelectedValue (which caused the postback) cannot be remembered?<asp:GridView ID="gridPendRoles" runat="server" CellPadding="5" AutoGenerateColumns="False" BackColor="#CCFFFF" BorderColor="Black" BorderStyle="Solid" onrowdeleting="gridPendRoles_RowDeleting" onrowediting="gridPendRoles_RowEditing" onrowcancelingedit="gridPendRoles_RowCancelingEdit" onrowupdating="gridPendRoles_RowUpdating"

View Complete Post

More Related Resource Links

1st PostBack only: SelectedIndexChanged events fire AND GridView & ReadOnly controls disappear

On initial load of the page, everything is visible & runs correct. On the first PostBack fired by any one of my DDLs, RadioBtns, LinkBtns that have the AutoPostBack=true property, then ddlPriority_SelectedIndexChanged & ddlPendUserReqType_SelectedIndexChanged events always fire (and only from these DDLs, the others don't fire inappropriately), even when neither of those controls had been selected. Then my GridView gridPendRoles disappears, unless a DataSource & DataBind() is forced. Any ReadOnly controls (lblTicketID, txbxInsertTicketDate, lblPendUserID) will also loose their data/text in the first PostBack. However, every PostBack following will not inappropriately fire events. And as long as a DataSource was set & DataBind() called a 2nd time at any time during any PostBack, the GridView will stay visible with correct data displayed. Again, as long as the ReadOnly controls have their data/text set a 2nd time during any PostBack, they too will retain their data/text for every following PostBack. I've tried debugging with Trace on & walked thru everything very thoroughly, but still cannot catch any reasons why this would occur. And since I am using the Delete & Edit command linkBtns in my GridView, I can't just force a DataSource & DataBind() on every PostBack, or I would loose those Row

disable autopostback of checkbox inside of GridView during SelectedIndexChanged of ListView

Hi, I hope my question is clear: I have a checkbox placed inside a gridview: <GridView><asp:TemplateField HeaderText="Driver">   <ItemTemplate>       <asp:CheckBox ID="CheckBoxDriver" AutoPostBack="true" OnCheckedChanged="GridView_Persons_SelectedIndexChanged" ValidationGroup='<%# Eval("ID") + "-" +((GridViewRow)Container).RowIndex %>' CssClass="CXDriver" runat="server" Checked='false' />   </ItemTemplate>       </GridView> For example: A listViewItem 1 has 3 drivers are checked, A listViewItem 2 has 2 drivers are checked. Therefore, if changing the selectedIndex of the list, the checkbox indexChanged event will be fired. How could I disable the autopostback of the checkbox during the listview item changed. Thanks in advance

Custom Grid View Header - Grid view Row Created event vs Gridview row databound events ?


Hi Gurus ,

It happened to add an extra Gridveiw Header in row_databound event , It did worked fine on !Postback but disappered on Page.Postback . Quick google search guided me to move the event to Row_Created event and every thing is okay .

Can any expert post some pointers , differnces between grid row_created vs row_databount with some sample table data created dynamically  behaviour of both the events in !Postback and page.Postback .

Thanks a tonne in Advance and  any inputs will be valued and appreciated .

DropDownLists and AutoPostBack

Hi,I have a web form with a number of DropDownLists on. The selection in each determines what data is displayed in the other lists, all of which data comes from a SQL server table. I've noticed that when I set AutoPostBack to true, the whole page refreshes when changing the selection within each list and I've also noticed that the values selected in the other lists are lost.Is there anyway which I can:1) Maintain values already selected across postbacks2) Stop the page refreshing each time a new item is selectedThanks in advance,Kev

How to Fire events on SharePoint DateTime Control in visual web part

Hi All, I am working on visual webpart of SharePoint 2010. I am using a <SharePoint:DateTimeControl> i m trying  to fire OnDateChanged event on it. I am not getting the Appropriate way to create the event. please help me out!!!!   void ToDate_OnDateChanged(object sender, EventArgs e)         {                         if (ToDate != null)             {                 DateTime min = Convert.ToDateTime(FromDate.SelectedDate.ToString());                 DateTime max = Convert.ToDateTime(ToDate.SelectedDate.ToString());                 int noofdays = Convert.ToInt32((max - min).TotalDays);                 txtNoOfDays.Text = noofdays.ToString();             }         }    <SharePoint:DateTimeControl runat="server" Calendar="Gregorian"  

Dropdownlist not firing SelectedIndexChanged on first item with autopostback true

Hi: Has anyone ever found a work around for the well documented and well known bug, the dropdownlist bug? Specifically where the SelectedIndexChange event does not fire on the first listitem, althought both autopostback and enableviewstate are true? In other words, if the first three items in the dropdownlist are red, blue, green, if you select green, the SelectedIndexChanged will fire, but if you then select red, the first item in the ddl, the event will not fire. All listitems will fire the SelectedIndexChanged event, except for the very first listitem. The HACK has always been to include a dummy item as the first list time like"Select a Color" to get around the first item bug. I have got a situation where I cannot use that hack. Ideas?  TIA, Bill  

Gridview, MasterPage, Ajax, AutoPostback and FRUSTRATION

I have a peice of code for a custom Gridview that works great if it is not in my Master.Page. As soon as I put it in my masterpage /ajax update panel it seems the autopostback function of my checkbox stops working.... please advice. Here is the relevent code :   NOTE: (I have tried to turn on ViewState in every thing I could think of.....still nothing) <asp:GridView ID="gvHR" CssClass="gridview" runat="server" AllowPaging="True" EnableViewState="true" DataKeyNames="HRID" AutoGenerateColumns="False" DataSourceID="ldsHR"> <Columns> <asp:BoundField DataField="FirstName" HeaderText="FirstName" ReadOnly="True" SortExpression="FirstName" /> <asp:BoundField DataField="LastName" HeaderText="LastName" ReadOnly="True" SortExpression="LastName" /> <asp:BoundField DataField="EmailName" HeaderText="EmailName" ReadOnly="True" SortExpression="EmailName" /> <asp:TemplateField HeaderText="LeftCompany" SortExpression="LeftCompany&quo

Weird behaviour of Gridview with textbox with autopostback OnTextChanged and AJAX CalendarExtender

I ran in to some strange behaviour of Gridview with textbox with autopostback OnTextChanged and AJAX CalendarExtender. This gridview is in an updatepanel with scriptmanager. When my gridview is filled with data, it keeps running my OnTextChanged  function and therefor makes my application terribly slow. I need to have the autopostback and ontextchanged function to recalculate stuff in my gridview. Does anybody know of this problem and if so does anybody found a workarround ?

autopostback problem in gridview why it show multiples times...


    <form id="form1" runat="server">
        <asp:DropDownList ID="DropDownList9" runat="server" DataSourceID="SC" DataTextField="ItemNo"
            DataValueField="ItemNo" Style=" left: 131px; position: absolute;
            top: 41px; z-index: 104;" OnSelectedIndexChanged="DropDownList9_SelectedIndexChanged" TabIndex="12" AutoPostBack="True" OnDataBound="DropDownList9_DataBound">
        <asp:GridView style="Z-INDEX: 101; LEFT: 14px; POSITION: absolute; TOP: 183px; width: 953px;" 
        id="Gridview1" runat="server" Height="127px" ForeColor="Teal" Font-Size="12pt" 
        Font-Names="Palatino Linotype" Font-Bold="True" Visible="False" 
        BorderColor="Transparent" OnRowDataBound="Gridview1_RowDataBound" 
        ShowFooter="True" SelectedIndex="5" OnRowCreated="Gridview1_RowCreated" 
        GridLines="None" CellSpacing="2" AutoGenerateColumns="False"><Columns>
<asp:BoundField DataField="RowNumber

Gridview with LinkButtons to handle events that update AjaxUpdatePanel


I have a Gridview displaying Titles.

I would like those titles to be LinkButtons that would cause event to update an AJAX UpdatePanel containing details about the Projects.

I would not like the Gridview to be in the Ajax UpdatePanel and refresh on every click, rather just refresh the UpdatePanel.

Can someone direct me in a direction to achieve this?

Session Events of Global.asax doesn't fire in sharepoint

As I have some requiremnt, i've written some code in session_start and session_end events in global.asax of the sharepoint web applicaion. But the events don't fire when the user logs in or logs out. Even the application_start also not working when the application starts. So do i need to make any changes in web.config or anywhere ? Please help.

Clicks dont fire events


Why does adding this line to the web.config....

<add path="ScriptResource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>

...cause postbacks click to stop occuring when I use LoadControl with UpdatePanels?

If I remove the line it works fine. If I remove the UpdatePanel it works fine.

What is it with these as a combination?

I inherited this web.config and am not sure why this was added in the first place... but I am not just gonna rip it out without understanding it first.

GridView and Firefox (does not appear the same as in IE and does not fire the command


Greets, my gridview works fine in IE but in Firefox it is problematic.

My gridview displays 4 columns where in the fourth i have an  asp:ButtonField

When i have one row in the results and the user hits the Button it does not fire in Firefox. In IE works fine.

My gridview is inside an asp:UpdatePanel and the page uses a masterpagefile.


On the other hand the text in the headers does not stay centered, altough i use 



Any ideas? Thanks

Gridview SelectedIndexChanged on a dynamically created gridview


my html page is basically a panel

Programmatically i've created the entire page adding controls to the panel. I have a dynamically created Accordion and within each accordion pane i have a dynamic gridview based on the properties for the accordion pane. Each row within the GridView i have a Button with the CommandName of Select, with this i want to open a new window and go to a new URL with the properties in a BoundField. On postback i want to be able to return to the Accordion.SelectedIndex. 

The problem is i can't seem to use a findControl to capture the index of either the GridView or Accordion. Below is my code:

AjaxControlToolkit.Accordion accordion = new AjaxControlToolkit.Accordion();
        accordion.ID = "Accordion2";
        accordion.HeaderCssClass = "accordionHeader";
        accordion.ContentCssClass = "accordionContent";
        accordion.HeaderSelectedCssClass = "accordionHeaderSelected";
        accordion.FramesPerSecond = 100;
        accordion.TransitionDuration = 100;
        accordion.FadeTransitions = true;
        accordion.EnableViewState = true;
        if (Session["myAccordion.SelectedIndex"] != null)
            accordion.SelectedIndex = (int)Session["myAccordion.SelectedIndex"];


Update databse with DropDownList in GridView, SelectedIndexChanged


I am new to asp.net (I may use some incorrect termology while I explain my issue...) and need some help with DropDownList in Gridview.  Currently I have a GridView set up with three Columns bound to a database: Column1 - some kinda of index, Column2 - string, Column3 - DropDownList(called Active).  So far when I build the page, all the columns show up and the DropDownList appears and the values are bound correctly.  I want to change a value in the DropDownList and automatically update that value in my database. 

I have set AutoPostBack = true and I made a DataObject (called UpdateActive) to update the database (it takes 2 inputs, the Column1 index and Column3 DropDownList value).  However, I don't know how to find the row that I am changing, is there a way to figure out what row it is (like finding the Column 1 index?).  Also, I don't want to have to click a button to update the data.

                        <asp:GridView ID="gvWorkflowStepOrder" runat="server" AllowPaging="True" AllowSorting="true"
AutoGenerateColumns="False" DataKeyNames="WorkflowStepOrderID" PageSize="50"

Disabling ViewState for DropDownList and using AutoPostback with SelectedIndexChanged


The sites I mantain are using way too much ViewState and I'd like to reduce that so the size of the page is reduced.  I've done a lot to remedy this but I have an issue relating to DropDown lists that use AutoPostbacks.

I have a dropdown list with a lot of list items and a good part of the ViewState usage is to hold the list item data.  If I disable ViewState and set the AutoPostBack property to true, the page will post back and in the page load I am trying to repopulate the dropdown list with cached data.  However, it seems that the SelectedIndexChanged event doesn't fire when EnableViewState="false".

Is it possible to make this work without enabling ViewState for the drodown list?

gridview postback on editTemplate


Hi Experts ,

Not sure whether this is possible even.

I have a gridview with EditTemplate. The column headings in the database for the gridview ProjectID(Unique),ProjectName,IsSubproject(Yes or No flag), SubprojectName.

If the IsSubproject column in the gridview is a checkbox while the SubprojectName is selected from a dropdown list. If checkbox is checked in edit mode I need to enable the dropdown list. Here is one postback I need.

In the dropdown list there is all the subprojects from the database and a new item "AddNew". If the user selects "AddNew" I need to enable and make visible true a textbox so that user can enter a new subproject. Here is the other postback I need.

Can I do these?

Some code help would be great.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend