473,756 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView Update doesn't update on first postback

Here's my GridView and my SqlDataSource

<asp:GridView ID="ContactHist oryGrid" runat="server"
AutoGenerateCol umns="False" DataSourceID="C ontactHistoryDS "
DataKeyNames="J obHistoryID"
OnRowCreated="C ontactHistoryGr id_RowCreated"
CssClass="GridV iewTable"
GridLines="None " CellSpacing="1" CellPadding="3" AllowSorting="T rue"
AllowPaging="Tr ue">
<EmptyDataTempl ate>
<div class="NoResult sPanel">
No items were found for your search.
</div>
</EmptyDataTempla te>
<PagerTemplat e>
<div style="float: right;">
<asp:Button ID="NextButton " runat="server" Text="Next"
CommandName="Pa ge" CommandArgument ="Next" />
<asp:Button ID="LastButton " runat="server" Text="Last"
CommandName="Pa ge" CommandArgument ="Last" />
</div>
<div style="float: left;">
<asp:Button ID="FirstButton " runat="server" Text="First"
CommandName="Pa ge" CommandArgument ="First" />
<asp:Button ID="PrevButton " runat="server" Text="Prev"
CommandName="Pa ge" CommandArgument ="Prev" />
</div>
Page <asp:DropDownLi st ID="PageDropDow n" runat="server"
AutoPostBack="t rue" />
of <asp:Literal ID="PageCountLi teral" runat="server" />

</PagerTemplate>
<PagerSetting s Position="TopAn dBottom" />
<PagerStyle CssClass="table SmallHeaderCell " />
<Columns>
<asp:BoundFie ld DataField="Cust omerName" HeaderText="Com pany"
ReadOnly="True" SortExpression= "CustomerNa me" >
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:BoundField>
<asp:BoundFie ld DataField="Posi tion" HeaderText="Pos ition"
SortExpression= "Position" >
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:BoundField>
<asp:TemplateFi eld HeaderText="Sta rt Date"
SortExpression= "StartDate" >
<EditItemTempla te>
<asp:TextBox ID="EditStartDa teTextBox" runat="server" Text='<%#
Bind("StartDate ", "{0:MMM d, yyyy}") %>' />
<asp:HyperLin k ID="StartDateCa lendarLink" runat="server"
ImageUrl="~/images/calendarButton. png" />
</EditItemTemplat e>
<ItemTemplate >
<asp:Literal ID="StartDateLi teral" runat="server" Text='<%#
Eval("StartDate ", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="End Date" SortExpression= "EndDate">
<EditItemTempla te>
<asp:TextBox ID="EditEndDate TextBox" runat="server" Text='<%#
Bind("EndDate", "{0:MMM d, yyyy}") %>' />
<asp:HyperLin k ID="EndDateCale ndarLink" runat="server"
ImageUrl="~/images/calendarButton. png" />
</EditItemTemplat e>
<ItemTemplate >
<asp:Literal ID="EndDateLite ral" runat="server" Text='<%#
Eval("EndDate", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:TemplateFie ld>
<asp:CommandFie ld ButtonType="But ton" ShowEditButton= "True">
<HeaderStyle CssClass="table SmallHeaderCell " />
<ItemStyle CssClass="table DataCell" />
</asp:CommandFiel d>
</Columns>
</asp:GridView>

<asp:SqlDataSou rce ID="ContactHist oryDS" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:SalesCRM %>" ProviderName="< %
$ ConnectionStrin gs:SalesCRM.Pro viderName %>"
SelectCommand=" SELECT ContactID, FirstName, LastName, JobHistoryID,
CustomerNumber, CustomerName, Position, StartDate, EndDate FROM
dbo.ContactJobH istory_V WHERE ContactID = @contactid AND EndDate IS
NOT NULL" SelectCommandTy pe="text"
UpdateCommand=" dbo.UpdateJob_u sp"
UpdateCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:QueryStrin gParameter Name="contactid "
QueryStringFiel d="contactid" />
</SelectParameter s>
</asp:SqlDataSour ce>

Here's my OnRowCreatedEve nt:

protected void ContactHistoryG rid_RowCreated (object sender,
GridViewRowEven tArgs e) {
GridView gv = (GridView) sender;
if (e.Row.RowType == DataControlRowT ype.Header) {
// Apply the sorting arrows to the header as needed.
GridViewFunctio ns.AddSortArrow (gv, e);
} else if (e.Row.RowType == DataControlRowT ype.Pager) {
// Setup the paging buttons (enable/disable the buttons, attach the
proper event function to the dropdownlist)
Button first = (Button) e.Row.Cells[0].FindControl ("FirstButton") ;
Button previous = (Button) e.Row.Cells[0].FindControl
("PrevButton ");
Button next = (Button) e.Row.Cells[0].FindControl ("NextButton ");
Button last = (Button) e.Row.Cells[0].FindControl ("LastButton ");
DropDownList pageSelect = (DropDownList) e.Row.Cells[0].FindControl
("PageDropDown" );
Literal pageCount = (Literal) e.Row.Cells[0].FindControl
("PageCountLite ral");
GridViewFunctio ns.InitializeBu ttonPager (gv, e, first, previous,
pageSelect, pageCount, next, last);
} else if (e.Row.RowType == DataControlRowT ype.DataRow &&
((e.Row.RowStat e == (DataControlRow State.Alternate |
DataControlRowS tate.Edit)) || e.Row.RowState ==
DataControlRowS tate.Edit)) {
// Set the proper javascript function for the image link to open
the popup calendar
string script = "javascript:ope nCalendar('{0}' , '{1}');";
HyperLink calLink = (HyperLink) e.Row.FindContr ol
("StartDateCale ndarLink");
TextBox startDateTB = (TextBox) e.Row.FindContr ol
("EditStartDate TextBox");
DataRowView dataItem = (DataRowView) e.Row.DataItem;
if (dataItem != null) {
string startDateString = ((DateTime)
dataItem.Row.It emArray[7]).ToString ("d-MMM-yyyy");
calLink.Navigat eUrl = String.Format (script, startDateTB.Cli entID,
Server.UrlEncod e (startDateStrin g));
}
}
}

The premise here is that in the row that gets edited, I have a textbox
with a link to open a pop-up calendar, that will write back the value
to the text box. That part works. The problem is when I try to click
the update button. The page postsback, but it doesn't leave the "edit"
mode. Instead, it comes back and all the textboxes are now blank. If I
type the values back into the textboxes and submit a second time, my
database gets updated, it leaves edit mode, etc (in other words, it
works). If I remove the third else condition in my RowCreated event,
the page works as expected form the get-go (only need to postback once
to have the update occur), but I obviously lose out on my pop-up
calendar.

Anyone got any clues what is going on here?

Apr 18 '07 #1
1 10406
On Apr 18, 9:07 am, "Evan M." <emorgoch.pub.. .@gmail.comwrot e:
Here's my GridView and my SqlDataSource

<asp:GridView ID="ContactHist oryGrid" runat="server"
AutoGenerateCol umns="False" DataSourceID="C ontactHistoryDS "
DataKeyNames="J obHistoryID"
OnRowCreated="C ontactHistoryGr id_RowCreated"
CssClass="GridV iewTable"
GridLines="None " CellSpacing="1" CellPadding="3" AllowSorting="T rue"
AllowPaging="Tr ue">
<EmptyDataTempl ate>
<div class="NoResult sPanel">
No items were found for your search.
</div>
</EmptyDataTempla te>
<PagerTemplat e>
<div style="float: right;">
<asp:Button ID="NextButton " runat="server" Text="Next"
CommandName="Pa ge" CommandArgument ="Next" />
<asp:Button ID="LastButton " runat="server" Text="Last"
CommandName="Pa ge" CommandArgument ="Last" />
</div>
<div style="float: left;">
<asp:Button ID="FirstButton " runat="server" Text="First"
CommandName="Pa ge" CommandArgument ="First" />
<asp:Button ID="PrevButton " runat="server" Text="Prev"
CommandName="Pa ge" CommandArgument ="Prev" />
</div>
Page <asp:DropDownLi st ID="PageDropDow n" runat="server"
AutoPostBack="t rue" />
of <asp:Literal ID="PageCountLi teral" runat="server" />

</PagerTemplate>
<PagerSetting s Position="TopAn dBottom" />
<PagerStyle CssClass="table SmallHeaderCell " />
<Columns>
<asp:BoundFie ld DataField="Cust omerName" HeaderText="Com pany"
ReadOnly="True" SortExpression= "CustomerNa me" >
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:BoundField>
<asp:BoundFie ld DataField="Posi tion" HeaderText="Pos ition"
SortExpression= "Position" >
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:BoundField>
<asp:TemplateFi eld HeaderText="Sta rt Date"
SortExpression= "StartDate" >
<EditItemTempla te>
<asp:TextBox ID="EditStartDa teTextBox" runat="server" Text='<%#
Bind("StartDate ", "{0:MMM d, yyyy}") %>' />
<asp:HyperLin k ID="StartDateCa lendarLink" runat="server"
ImageUrl="~/images/calendarButton. png" />
</EditItemTemplat e>
<ItemTemplate >
<asp:Literal ID="StartDateLi teral" runat="server" Text='<%#
Eval("StartDate ", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:TemplateFie ld>
<asp:TemplateFi eld HeaderText="End Date" SortExpression= "EndDate">
<EditItemTempla te>
<asp:TextBox ID="EditEndDate TextBox" runat="server" Text='<%#
Bind("EndDate", "{0:MMM d, yyyy}") %>' />
<asp:HyperLin k ID="EndDateCale ndarLink" runat="server"
ImageUrl="~/images/calendarButton. png" />
</EditItemTemplat e>
<ItemTemplate >
<asp:Literal ID="EndDateLite ral" runat="server" Text='<%#
Eval("EndDate", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="table DataCell" />
<HeaderStyle CssClass="table SmallHeaderCell " />
</asp:TemplateFie ld>
<asp:CommandFie ld ButtonType="But ton" ShowEditButton= "True">
<HeaderStyle CssClass="table SmallHeaderCell " />
<ItemStyle CssClass="table DataCell" />
</asp:CommandFiel d>
</Columns>
</asp:GridView>

<asp:SqlDataSou rce ID="ContactHist oryDS" runat="server"
ConnectionStrin g="<%$ ConnectionStrin gs:SalesCRM %>" ProviderName="< %
$ ConnectionStrin gs:SalesCRM.Pro viderName %>"
SelectCommand=" SELECT ContactID, FirstName, LastName, JobHistoryID,
CustomerNumber, CustomerName, Position, StartDate, EndDate FROM
dbo.ContactJobH istory_V WHERE ContactID = @contactid AND EndDate IS
NOT NULL" SelectCommandTy pe="text"
UpdateCommand=" dbo.UpdateJob_u sp"
UpdateCommandTy pe="StoredProce dure">
<SelectParamete rs>
<asp:QueryStrin gParameter Name="contactid "
QueryStringFiel d="contactid" />
</SelectParameter s>
</asp:SqlDataSour ce>

Here's my OnRowCreatedEve nt:

protected void ContactHistoryG rid_RowCreated (object sender,
GridViewRowEven tArgs e) {
GridView gv = (GridView) sender;
if (e.Row.RowType == DataControlRowT ype.Header) {
// Apply the sorting arrows to the header as needed.
GridViewFunctio ns.AddSortArrow (gv, e);
} else if (e.Row.RowType == DataControlRowT ype.Pager) {
// Setup the paging buttons (enable/disable the buttons, attach the
proper event function to the dropdownlist)
Button first = (Button) e.Row.Cells[0].FindControl ("FirstButton") ;
Button previous = (Button) e.Row.Cells[0].FindControl
("PrevButton ");
Button next = (Button) e.Row.Cells[0].FindControl ("NextButton ");
Button last = (Button) e.Row.Cells[0].FindControl ("LastButton ");
DropDownList pageSelect = (DropDownList) e.Row.Cells[0].FindControl
("PageDropDown" );
Literal pageCount = (Literal) e.Row.Cells[0].FindControl
("PageCountLite ral");
GridViewFunctio ns.InitializeBu ttonPager (gv, e, first, previous,
pageSelect, pageCount, next, last);
} else if (e.Row.RowType == DataControlRowT ype.DataRow &&
((e.Row.RowStat e == (DataControlRow State.Alternate |
DataControlRowS tate.Edit)) || e.Row.RowState ==
DataControlRowS tate.Edit)) {
// Set the proper javascript function for the image link to open
the popup calendar
string script = "javascript:ope nCalendar('{0}' , '{1}');";
HyperLink calLink = (HyperLink) e.Row.FindContr ol
("StartDateCale ndarLink");
TextBox startDateTB = (TextBox) e.Row.FindContr ol
("EditStartDate TextBox");
DataRowView dataItem = (DataRowView) e.Row.DataItem;
if (dataItem != null) {
string startDateString = ((DateTime)
dataItem.Row.It emArray[7]).ToString ("d-MMM-yyyy");
calLink.Navigat eUrl = String.Format (script, startDateTB.Cli entID,
Server.UrlEncod e (startDateStrin g));
}
}
}

The premise here is that in the row that gets edited, I have a textbox
with a link to open a pop-up calendar, that will write back the value
to the text box. That part works. The problem is when I try to click
the update button. The page postsback, but it doesn't leave the "edit"
mode. Instead, it comes back and all the textboxes are now blank. If I
type the values back into the textboxes and submit a second time, my
database gets updated, it leaves edit mode, etc (in other words, it
works). If I remove the third else condition in my RowCreated event,
the page works as expected form the get-go (only need to postback once
to have the update occur), but I obviously lose out on my pop-up
calendar.

Anyone got any clues what is going on here?
Alright, I have a little bit more information:
It appears that the call to ClientID is what is throwing everything
off. If I don't call the clientID property, then when I do a
viewsource on the page output (before I submit the update), the id for
the textbox is stated as "ctl00$MainCont ent$ContactHist oryGrid
$ctl04$EditStar tDateTextBox" (as all the control within the edit row
are named).

However, if I do make the call to ClientID, then the ID of the textbox
BEFORE the first update postback is "EditStartDateT extBox" (and the
other controls are named similarily, missing the initial pre-amble).
When I do submit the update, the page comes back again still in edit
mode, but the textboxes are blank, and now all the clientIDs are set
to their preamble names.

It appears that calling ClientID from within the RowCreated event is
preventing some form of processing on the server side or something.

Anyone have any ideas abotu how I can work around this (short of doing
a manual setting of the ID including the preamble)?

Thanks,
Evan

Apr 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6250
by: nolan | last post by:
I have an asp.net 2.0 page with a gridview and detailsview on the same page set up in a master-details scenario. The gridview and detailsview have separate SQL data sources. The user enters search criteria in a text box and clicks a find button to initially populate the gridview with items of interest. I have added a select button to my gridview and when the user clicks the button the detailsview is populated perfectly. However, I also...
1
3528
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all javascript, nothing really having to do with ASP.NET... I'm attempting to put together an application that consists of several GridView controls each bound to some xml data. Each table exists in its own update panel. The two effects I'm going for are:
3
13406
by: cpnet | last post by:
I have a GridView which I'm populating from an ObjectDataSource (give the GridView a DataTable). The GridView will have about 20 rows, and only one editable column. The editable column consists of a RadioButtonList ("Yes", "No", "Not Answered") in a TemplateColumn. I want the user to be able to select a radio button for each row in the GridView (without having to first put each row into edit mode). Once the user has selected the Radio...
0
1992
by: =?Utf-8?B?TGFkaXNsYXYgTXJua2E=?= | last post by:
Hello, I read some msdn and other articles about how does databinding among DataSource controls and FormView / GridView controls works but I still don't fully understand to this blackbox. I have few questions and hopefully you can provide me some answers. 1. Best place for DataBinding. Where is the best place for calling DataBind method? Is it possible to say don't bind controls for this postback and use current values instead? These...
8
7734
by: gerry | last post by:
The PagerSettings.Visible property is not being handled properly by the GridView control. The value assigned to this property is not applied until after a postback. Simplest test : .aspx containing a single gridview - enable paging and give enough data to page. add checkbox with auto postback enable add button with auto postback enable in the GridView1_PreRender method add the following : GridView1.HeaderRow.Enabled =
4
2541
by: Mark Olbert | last post by:
I'm running into a well-described issue in the ASPNET model that I haven't found a good work around for. I have a GridView to which I dynamically add data-bound TemplateFields at run-time. The specific fields that are added depend on the state of the application. The contents of these fields displays properly after they are first initialized, but not after postback (e.g., just a simple button control that doesn't do anything except...
0
5951
by: =?Utf-8?B?Sm9l?= | last post by:
I have a gridview with buttons in a column and I want those buttons to be triggers for an update panel further down on the page. So for example, when a user clicks on the button in row 3, I want an async postback to occur and an update panel in a different section of the page to update and display "Row 3 was clicked". The gridview is outside of the update panel. How can I accomplish this? The update panel does not seem to support...
11
6067
by: SAL | last post by:
Hello, I have a Gridview control (.net 2.0) that I'm having trouble getting the Update button to fire any kind of event or preforming the update. The datatable is based on a join so I don't know if that's what's causing the behavior or not. It seems like the Update button should at least do something. When the Edit button is clicked, the grid goes into Edit mode and the Cancel button takes the grid out of Edit mode. So, I don't get what...
4
12025
by: BiffMaGriff | last post by:
Hello, I have a GridView that I put inside an update panel. I have a control that attaches to the datasource of the gridview that filters the data, databinds the gridview and then updates the update panel that the gridview is in. In my page render I put this so I could select a row by just clicking it. protected override void Render(HtmlTextWriter writer) {
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.