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 <asp:DropDownList 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 = "javascript:openCalendar('{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? 1 10270
On Apr 18, 9:07 am, "Evan M." <emorgoch.pub...@gmail.comwrote:
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 <asp:DropDownList 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 = "javascript:openCalendar('{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?
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$MainContent$ContactHistoryGrid
$ctl04$EditStartDateTextBox" (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 "EditStartDateTextBox" (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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: erikbower65 |
last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps:
1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal.
2. Connect to...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: Mushico |
last post by:
How to calculate date of retirement from date of birth
| |