E
Evan M.
Here's my GridView and my SqlDataSource
<asp:GridView ID="ContactHistoryGrid" runat="server"
AutoGenerateColumns="False" DataSourceID="ContactHistoryDS"
DataKeyNames="JobHistoryID"
OnRowCreated="ContactHistoryGrid_RowCreated"
CssClass="GridViewTable"
GridLines="None" CellSpacing="1" CellPadding="3" AllowSorting="True"
AllowPaging="True">
<EmptyDataTemplate>
<div class="NoResultsPanel">
No items were found for your search.
</div>
</EmptyDataTemplate>
<PagerTemplate>
<div style="float: right;">
<asp:Button ID="NextButton" runat="server" Text="Next"
CommandName="Page" CommandArgument="Next" />
<asp:Button ID="LastButton" runat="server" Text="Last"
CommandName="Page" CommandArgument="Last" />
</div>
<div style="float: left;">
<asp:Button ID="FirstButton" runat="server" Text="First"
CommandName="Page" CommandArgument="First" />
<asp:Button ID="PrevButton" runat="server" Text="Prev"
CommandName="Page" CommandArgument="Prev" />
</div>
Page <aspropDownList ID="PageDropDown" runat="server"
AutoPostBack="true" />
of <asp:Literal ID="PageCountLiteral" runat="server" />
</PagerTemplate>
<PagerSettings Position="TopAndBottom" />
<PagerStyle CssClass="tableSmallHeaderCell" />
<Columns>
<asp:BoundField DataField="CustomerName" HeaderText="Company"
ReadOnly="True" SortExpression="CustomerName" >
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:BoundField>
<asp:BoundField DataField="Position" HeaderText="Position"
SortExpression="Position" >
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:BoundField>
<asp:TemplateField HeaderText="Start Date"
SortExpression="StartDate">
<EditItemTemplate>
<asp:TextBox ID="EditStartDateTextBox" runat="server" Text='<%#
Bind("StartDate", "{0:MMM d, yyyy}") %>' />
<asp:HyperLink ID="StartDateCalendarLink" runat="server"
ImageUrl="~/images/calendarButton.png" />
</EditItemTemplate>
<ItemTemplate>
<asp:Literal ID="StartDateLiteral" runat="server" Text='<%#
Eval("StartDate", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:TemplateField>
<asp:TemplateField HeaderText="EndDate" SortExpression="EndDate">
<EditItemTemplate>
<asp:TextBox ID="EditEndDateTextBox" runat="server" Text='<%#
Bind("EndDate", "{0:MMM d, yyyy}") %>' />
<asp:HyperLink ID="EndDateCalendarLink" runat="server"
ImageUrl="~/images/calendarButton.png" />
</EditItemTemplate>
<ItemTemplate>
<asp:Literal ID="EndDateLiteral" runat="server" Text='<%#
Eval("EndDate", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="True">
<HeaderStyle CssClass="tableSmallHeaderCell" />
<ItemStyle CssClass="tableDataCell" />
</asp:CommandField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ContactHistoryDS" runat="server"
ConnectionString="<%$ ConnectionStrings:SalesCRM %>" ProviderName="<%
$ ConnectionStrings:SalesCRM.ProviderName %>"
SelectCommand="SELECT ContactID, FirstName, LastName, JobHistoryID,
CustomerNumber, CustomerName, Position, StartDate, EndDate FROM
dbo.ContactJobHistory_V WHERE ContactID = @contactid AND EndDate IS
NOT NULL" SelectCommandType="text"
UpdateCommand="dbo.UpdateJob_usp"
UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter Name="contactid"
QueryStringField="contactid" />
</SelectParameters>
</asp:SqlDataSource>
Here's my OnRowCreatedEvent:
protected void ContactHistoryGrid_RowCreated (object sender,
GridViewRowEventArgs e) {
GridView gv = (GridView) sender;
if (e.Row.RowType == DataControlRowType.Header) {
// Apply the sorting arrows to the header as needed.
GridViewFunctions.AddSortArrow (gv, e);
} else if (e.Row.RowType == DataControlRowType.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
("PageCountLiteral");
GridViewFunctions.InitializeButtonPager (gv, e, first, previous,
pageSelect, pageCount, next, last);
} else if (e.Row.RowType == DataControlRowType.DataRow &&
((e.Row.RowState == (DataControlRowState.Alternate |
DataControlRowState.Edit)) || e.Row.RowState ==
DataControlRowState.Edit)) {
// Set the proper javascript function for the image link to open
the popup calendar
string script = "javascriptpenCalendar('{0}', '{1}');";
HyperLink calLink = (HyperLink) e.Row.FindControl
("StartDateCalendarLink");
TextBox startDateTB = (TextBox) e.Row.FindControl
("EditStartDateTextBox");
DataRowView dataItem = (DataRowView) e.Row.DataItem;
if (dataItem != null) {
string startDateString = ((DateTime)
dataItem.Row.ItemArray[7]).ToString ("d-MMM-yyyy");
calLink.NavigateUrl = String.Format (script, startDateTB.ClientID,
Server.UrlEncode (startDateString));
}
}
}
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?
<asp:GridView ID="ContactHistoryGrid" runat="server"
AutoGenerateColumns="False" DataSourceID="ContactHistoryDS"
DataKeyNames="JobHistoryID"
OnRowCreated="ContactHistoryGrid_RowCreated"
CssClass="GridViewTable"
GridLines="None" CellSpacing="1" CellPadding="3" AllowSorting="True"
AllowPaging="True">
<EmptyDataTemplate>
<div class="NoResultsPanel">
No items were found for your search.
</div>
</EmptyDataTemplate>
<PagerTemplate>
<div style="float: right;">
<asp:Button ID="NextButton" runat="server" Text="Next"
CommandName="Page" CommandArgument="Next" />
<asp:Button ID="LastButton" runat="server" Text="Last"
CommandName="Page" CommandArgument="Last" />
</div>
<div style="float: left;">
<asp:Button ID="FirstButton" runat="server" Text="First"
CommandName="Page" CommandArgument="First" />
<asp:Button ID="PrevButton" runat="server" Text="Prev"
CommandName="Page" CommandArgument="Prev" />
</div>
Page <aspropDownList ID="PageDropDown" runat="server"
AutoPostBack="true" />
of <asp:Literal ID="PageCountLiteral" runat="server" />
</PagerTemplate>
<PagerSettings Position="TopAndBottom" />
<PagerStyle CssClass="tableSmallHeaderCell" />
<Columns>
<asp:BoundField DataField="CustomerName" HeaderText="Company"
ReadOnly="True" SortExpression="CustomerName" >
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:BoundField>
<asp:BoundField DataField="Position" HeaderText="Position"
SortExpression="Position" >
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:BoundField>
<asp:TemplateField HeaderText="Start Date"
SortExpression="StartDate">
<EditItemTemplate>
<asp:TextBox ID="EditStartDateTextBox" runat="server" Text='<%#
Bind("StartDate", "{0:MMM d, yyyy}") %>' />
<asp:HyperLink ID="StartDateCalendarLink" runat="server"
ImageUrl="~/images/calendarButton.png" />
</EditItemTemplate>
<ItemTemplate>
<asp:Literal ID="StartDateLiteral" runat="server" Text='<%#
Eval("StartDate", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:TemplateField>
<asp:TemplateField HeaderText="EndDate" SortExpression="EndDate">
<EditItemTemplate>
<asp:TextBox ID="EditEndDateTextBox" runat="server" Text='<%#
Bind("EndDate", "{0:MMM d, yyyy}") %>' />
<asp:HyperLink ID="EndDateCalendarLink" runat="server"
ImageUrl="~/images/calendarButton.png" />
</EditItemTemplate>
<ItemTemplate>
<asp:Literal ID="EndDateLiteral" runat="server" Text='<%#
Eval("EndDate", "{0:MMM d, yyyy}") %>' />
</ItemTemplate>
<ItemStyle CssClass="tableDataCell" />
<HeaderStyle CssClass="tableSmallHeaderCell" />
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="True">
<HeaderStyle CssClass="tableSmallHeaderCell" />
<ItemStyle CssClass="tableDataCell" />
</asp:CommandField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="ContactHistoryDS" runat="server"
ConnectionString="<%$ ConnectionStrings:SalesCRM %>" ProviderName="<%
$ ConnectionStrings:SalesCRM.ProviderName %>"
SelectCommand="SELECT ContactID, FirstName, LastName, JobHistoryID,
CustomerNumber, CustomerName, Position, StartDate, EndDate FROM
dbo.ContactJobHistory_V WHERE ContactID = @contactid AND EndDate IS
NOT NULL" SelectCommandType="text"
UpdateCommand="dbo.UpdateJob_usp"
UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter Name="contactid"
QueryStringField="contactid" />
</SelectParameters>
</asp:SqlDataSource>
Here's my OnRowCreatedEvent:
protected void ContactHistoryGrid_RowCreated (object sender,
GridViewRowEventArgs e) {
GridView gv = (GridView) sender;
if (e.Row.RowType == DataControlRowType.Header) {
// Apply the sorting arrows to the header as needed.
GridViewFunctions.AddSortArrow (gv, e);
} else if (e.Row.RowType == DataControlRowType.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
("PageCountLiteral");
GridViewFunctions.InitializeButtonPager (gv, e, first, previous,
pageSelect, pageCount, next, last);
} else if (e.Row.RowType == DataControlRowType.DataRow &&
((e.Row.RowState == (DataControlRowState.Alternate |
DataControlRowState.Edit)) || e.Row.RowState ==
DataControlRowState.Edit)) {
// Set the proper javascript function for the image link to open
the popup calendar
string script = "javascriptpenCalendar('{0}', '{1}');";
HyperLink calLink = (HyperLink) e.Row.FindControl
("StartDateCalendarLink");
TextBox startDateTB = (TextBox) e.Row.FindControl
("EditStartDateTextBox");
DataRowView dataItem = (DataRowView) e.Row.DataItem;
if (dataItem != null) {
string startDateString = ((DateTime)
dataItem.Row.ItemArray[7]).ToString ("d-MMM-yyyy");
calLink.NavigateUrl = String.Format (script, startDateTB.ClientID,
Server.UrlEncode (startDateString));
}
}
}
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?