I added 3 updatepanel on a aspx page.Two updatepanel includes gridview.And i make gridview paging.two buttons fill this gridviews when clicked.I set both of them triggers and conditional state.Third updatepanel includes textbox.And i set updatemode conditional,triggers third button.
That my question,when i click firstly third button i select checked datafield from gridview,run succesfully.
But when i click after one clicked,third updatepanel and gridview paging is not working.
<asp:UpdatePanel ID="UpdatePanelWorkFLow" runat="server">
<%--<Triggers>
<asp:PostBackTrigger ControlID="btnGenerate" />
</Triggers>--%>
<ContentTemplate>
<asp:GridView ID="GridWorkFlow" runat="server" AllowPaging="True" AutoGenerateColumns="False"
EnableSortingAndPagingCallbacks="false" CellPadding="4" ForeColor="#333333" GridLines="None"
OnPageIndexChanging="GridWorkFlow_PageIndexChanging">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField ShowHeader="true" HeaderText="Seç">
<ItemTemplate>
<asp:CheckBox ID="checkWorkFlow" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="labelWorkFlowId" runat="server" Text='<%# Eval("WorkFlowId")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="WorkFlow Adi">
<ItemTemplate>
<asp:Label ID="labelWorkFlowName" runat="server" Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Birincil Entity Adi">
<ItemTemplate>
<asp:Label ID="labelPrimaryEntity" runat="server" Text='<%# Bind("PrimaryEntity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField Visible="true" HeaderText="Durum Açiklamasi">
<ItemTemplate>
<asp:Label ID="labelWorkFlowStaus" runat="server" Text='<%# GetStatusCodeText(DataBinder.Eval(Container.DataItem,"StatusCode"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnWorkFLow" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
my gridview paging code
WorkFlowDataBind();
GridWorkFlow.PageIndex = e.NewPageIndex;
GridWorkFlow.DataBind();
my third button code
string userQueryId = GetUserQueryId();
string userqueryName = GetUserQueryName();
string workFlowId = GetWorkFlowId();
string primaryEntityName = GetWorkFlowPrimaryEntity();
GetWorkFlowName();
my one and second button when clicked load gridview
Datatable dtUserQuery=GetDataTable();
GridUserQuery.DataSource = dtUserQuery;
GridUserQuery.DataBind()
How can i fix.
Logic is .. If you have one or more update panel in the same page then properties of all update panel should be same such as if update panel data are dependency on each other
Update Mode : Always
EnableViewState : true(if you are using it)
Or you can explicitly update the Update panel when mode is conditional
Let us say you have two update panel like up1 and up2.
You have placed the label in the up1 and the other form or button placed in the up2.
Now on the click event in the up2, label placed in the up1 should be updated without loading the full page. Set the following stuffs
Set EnableParitialRendering ='True'(Script Manager)
Set Update Mode :Conditional(up1)
Set Update Mode : Always (up2). All set up done here. On click of a button in the up2, do your work and call up1.Update(); That's all.
Related
When you create an edit button in every row of a Gridview using CommandField it displays update/cancel buttons after clicking, so you can accept/cancel changes.
However, I want an edit button that has tooltip text, and since CommandField doesn't have tooltip property, i used TemplateField. It worked with the delete button, but I'm having problems with the edit button:
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" AllowSorting="True"
DataMember="DefaultView"
DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
DataKeyNames=FIELD,FIELD,FIELD" CellPadding="4" ForeColor="#333333" Width="90%"
Height="90%" Font-Size="Small">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="FIELD" HeaderText="FIELD" ReadOnly="True"
SortExpression="FIELD" />
<asp:BoundField DataField="FIELD" HeaderText="FIELD"
SortExpression="FIELD" />
<asp:BoundField DataField="FIELD" HeaderText="FIELD"
SortExpression="FIELD" />
<asp:BoundField DataField="FIELD" HeaderText="FIELD" ReadOnly="True"
SortExpression="FIELD" />
<asp:BoundField DataField="FIELD" HeaderText="FIELD" ReadOnly="True"
SortExpression="FIELD" />
<asp:BoundField DataField="FIELD" HeaderText="FIELD"
SortExpression="FIELD" />
<asp:CommandField ButtonType="Image" Visible="true" EditText="Edit" ShowEditButton="True" EditImageUrl="images/pencil1.png"></asp:CommandField>
<asp:TemplateField >
<ItemTemplate>
<asp:ImageButton ID="deleteButton" runat="server" CommandName="Delete" Text="Delete"
OnClientClick="return confirm('¿Are you sure?');" ToolTip="delete" ImageUrl="images/DeleteRed1.png" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DBUserInterfaceConnectionString %>"
SelectCommand="SELECT ... FROM ... INNER JOIN ... ON ..."
DeleteCommand="DELETE FROM ... WHERE ...=#param;"
UpdateCommand="UPDATE ... SET ... = #param, ... = #param2 WHERE ... = #param3 and ... = #param4 and ... = #param5;"
>
</asp:SqlDataSource>
As I said before, I replaced CommandField with:
<asp:TemplateField >
<ItemTemplate>
<asp:ImageButton ID="editButton" runat="server" CommandName="Edit" Text="Edit" ToolTip="Edit" ImageUrl="images/pincel1.png" />
</ItemTemplate>
</asp:TemplateField >
but "Update/Cancel" buttons don't appear, so I can't update/edit anything. Why does it happen?
Any Ideas to implement a succesful edit button?
NOTES:
Both buttons don't have vb code behind, for some reason delete button works just with DeleteCommand in the SqlDataSource, and if I try to delete the command, it prompts error because no DeleteCommand is specified.
UpdateCommand has no purpose, it can be deleted. I could use it for a update button instead of an edit button, but when i tried, it says #params are not known, that's why I decided to use edit button instead.
The <asp:TemplateField> is used when you want to set your own-defined i.e. User-Defined content for each item in the GridView control.
The <asp:CommandField> is used when you want to use pre-defined command buttons to perform select, edit, or delete operations. Check MSDN here.
So, when your are using your own user-defined way for edit button, you also need to specify your custom content way for Update & Cancel button inside <EditItemTemplate> as :
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="editButton" runat="server" CommandName="Edit" Text="Edit"
ToolTip="Edit" ImageUrl="images/pincel1.png" />
</ItemTemplate>
<EditItemTemplate>
<asp:ImageButton ID="BtnUpdate" runat="server" CommandName="Update" Text="Update"
OnClick="BtnUpdate_Click" ImageUrl="images/Update.png"/>
<asp:ImageButton ID="BtnCancel" runat="server" CommandName="Cancel" Text="Cancel"
OnClick="BtnCancel_Click" ImageUrl="images/Cancel.png"/>
</EditItemTemplate>
</asp:TemplateField>
And just make sure, Only if you are again providing your Custom Implementation for Update & Cancel logic, you also define the onclick events for these two Update and Cancel buttons. Else remove the OnClick from markup of these buttons.
[ BtnUpdate_Click & BtnCancel_Click here.]
I think since you've converted it to a TemplateField, all of the automatically-functioning stuff (like Update/Cancel buttons) has been disabled. I'm betting you'll need to add an <EditItemTemplate> with the Update and Cancel buttons, and hook them to the relevant commands using CommandName.
I'm unable to identify the problem which is causing the edit command to fail
GridView Code
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="Requestid" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" Height="321px" Width="604px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField ShowEditButton="True" UpdateText="Submit" />
<asp:BoundField DataField="Requestid" HeaderText="Requestid" ReadOnly="True"
SortExpression="Requestid" />
<asp:BoundField DataField="Receiveddate" HeaderText="Receiveddate"
SortExpression="Receiveddate" />
<asp:BoundField DataField="Ctname" HeaderText="Ctname"
SortExpression="Ctname" />
<asp:TemplateField HeaderText="Requestor" SortExpression="Requestor">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="analystname"
DataValueField="contact_id" SelectedValue='<%# Bind("Requestor") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:Customers %>" SelectCommand="SELECT [contact_id], [first_name]+ space(1)+ [last_name] as analystname FROM [contact]
order by contact_id"></asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Requestor") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#CC3300" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#CBB06D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Customers %>" SelectCommand="SELECT RR.Requestid,Convert(varchar(20),RR.Receiveddate,100) as Receiveddate,RR.Ctname,C.First_Name +Space(1) + C.Last_NAME as Requestor from report_request_draft RR inner join Contact C on RR.requestor = C.contact_id
where clonedfromid is not null"
UpdateCommand="UPDATE [REPORT_REQUEST_DRAFT] SET [REQUESTOR] = #Requestor WHERE [requestid] = #requestid">
</asp:SqlDataSource>
When i click on the edit command button it gives me the below error
Error
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
The DropDownList can't be bound in this way. By using the SelectedValue binding as you have it, it requires that the DropDownList is bound before the GridView is bound, but that is a logical impossibility since the DropDownList can't be bound until the GridView has completed its binding. You should put this logic in the code behind with the RowDataBound event. At that point, you should manually bind your DropDownList and then set its SelectedValue property.
Consider the following link which will help you to solve your problem and it also shows you how to bind EditItemTemplet perfectly in grid View. I condenser you to use this link for better understand grid view.
I am facing little issue in my web application in asp.net.
i am receiving the below error :
Error: Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.
I have used Updatepanel and this error occurs when i try to do some 2-3 actions very quickly.
and when next time i try to do take some action my web application just hungs up.
Please suggest.
Thanks
In my case this was caused by having the 'Close' control within an Update Panel in the Modal Popup. I fixed it by creating a 'dummy' button outside of the Update Panel, and setting it as the 'CancelControlID' in the MPE attributes:
<asp:Button ID="btnDummyCloseWindow" runat="server" Style="visibility: hidden"/>
<ajaxToolkit:ModalPopupExtender ID="mpeWindow" runat="server" PopupControlID="pnlWindow"
TargetControlID="btnDummyOtherButton" BackgroundCssClass="modalBackground"
DropShadow="false" CancelControlID="btnDummyCloseWindow" />
You'll need to make sure the close button that is present within your Update Panel has actions assigned to it to close the window (e.g. mpeWindow.hide()).
It's also worth noting that I was also making use of the TargetControlID 'fix' too, where a dummy button is referenced, so ignore the TargetControlID attribute there.
I've solved the problem setting ScriptMode property of ScriptManager to Release instead of Debug
By default ScriptManager is set to Debug mode.
I had the same problem and solved by placing the ModalPopupExtender or the user control that uses ModalPopupExtender inside an update panel.
Which ever way you want to look at it, the problem is inherit in what I believe is a bug in AJAX.
The only way I was able to resolve this was to control your Sorting or Paging on the server side where you control or more specifically refresh the UpdatePanel along with making sure the ModalPopup has been kept visible!
The reason for the error is really because once you do a sort of page change on a GridView that's inside an UpdatePanel, the controls have been "lost" to the UpdatePanel.
A better explanation is here.
Here is a column from my GridView...
<asp:GridView ID="gvTETstudents" runat="server" AutoGenerateColumns="False" AllowSorting="True" CellPadding="4" ForeColor="#333333" Font-Size="Small" Width="100%"
DataSourceID="sdsTETstudents"
OnRowCreated="gvTETstudents_RowCreated"
OnRowDataBound="gvTETstudents_RowDataBound"
OnDataBound="gvTETstudents_DataBound">
<Columns>
..
..
<ItemTemplate>
<asp:UpdatePanel ID="upWEF1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnWEFCLOSE" />
</Triggers>
<ContentTemplate>
...
...
<asp:Panel ID="pnlWEF2" runat="server" style="display:none;">
<table><tr><td>
<asp:Button ID="btnWEFshow" runat="server"
Text="ALL"
Font-Size="Small" Font-Names="Arial"
ToolTip="Click here to see all of this student's work experience feedback on file" />
<ajaxToolkit:ModalPopupExtender ID="mpeWEF" runat="server"
BackgroundCssClass="modalBackground"
OkControlID="btnWEFCLOSE"
PopupControlID="upWEF2"
TargetControlID="btnWEFshow">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEF2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Panel ID="pnlWEF3" runat="server" CssClass="pnlEndorsed">
<div id="Hdr" style="text-align: center">
<asp:Label ID="lblWEFHdr" runat="server">** CONTACT LOG **</asp:Label>
</div>
<div id="Bdy">
<table style="width:100%"><tr><td>
<asp:GridView ID="gvWEFContactLog" runat="server"
Font-Size="X-Small" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="8" AllowSorting="True" AutoGenerateColumns="False" Width="100%"
DataKeyNames="StudentContactLogID,Private,ApprenticeContactLogID"
DataSourceID="sdsWEF"
OnRowDataBound="gvWEFContactLog_RowDataBound"
OnPageIndexChanging="gvWEFContactLog_PageIndexChanging"
OnSorted="gvWEFContactLog_Sorted">
<Columns>
<asp:TemplateField HeaderText="First Entered" SortExpression="FirstEntered">
<ItemTemplate>
<asp:HiddenField ID="hfWEFStudCLid" runat="server" Value='<%# Eval("StudentContactLogID") %>' />
<asp:HiddenField ID="hfWEFAppCLid" runat="server" Value='<%# Eval("ApprenticeContactLogID") %>' />
<asp:HiddenField ID="hfPrivate" runat="server" Value='<%# Eval("Private") %>' />
<asp:HiddenField ID="hfNotes" runat="server" Value='<%# Eval("ContactNotes") %>' />
<asp:LinkButton ID="lnkWEFCLOG" runat="server"
Text='<%# Eval("FirstEntered","{0:d MMM yyyy HH:mm}") %>'></asp:LinkButton>
<a id="lnkDummy" runat="server" visible=false></a>
<ajaxToolkit:ModalPopupExtender ID="mpeWEFCLOG" runat="server"
OkControlID="btnWEFCLOSEview"
PopupControlID="upWEFCLOG"
TargetControlID="lnkWEFCLOG">
</ajaxToolkit:ModalPopupExtender>
<asp:UpdatePanel ID="upWEFCLOG" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="pnlWEFCLOG" runat="server" class="pnlCLOG">
<asp:TextBox ID="txtWEFCLOG" runat="server"
Wrap="true"
TextMode="MultiLine"
Rows="10"
ReadOnly="true"
Width="98%">
</asp:TextBox>
<br />
<asp:Button ID="btnWEFCLOSEview" runat="server" Text="OK" Width="100%" />
</div>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" />
<asp:BoundField Visible="False" DataField="StudentContactLogID" HeaderText="LogID"
InsertVisible="False" ReadOnly="True" SortExpression="StudentContactLogID">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="StaffName" HeaderText="Staff" ReadOnly="True" SortExpression="StaffName" />
<asp:TemplateField HeaderText="Contact Date Time" SortExpression="ContactDateTime">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("ContactDateTime","{0:d MMM yyyy HH:mm}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Follow-Up Date" SortExpression="FollowUpDate">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("FollowUpDate","{0:d MMM yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Private" HeaderText="Private" SortExpression="Private" />
</Columns>
<EmptyDataTemplate>
No Current Entries
</EmptyDataTemplate>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="sdsWEF" runat="server" ConnectionString="<%$ ConnectionStrings:ATCNTV1ConnectionString %>"
SelectCommand="spTETStudentContactLogView" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="StudentID" Type="string" />
<asp:Parameter Name="WEF" Type="string" DefaultValue="%" />
</SelectParameters>
</asp:SqlDataSource>
</td></tr>
<tr style="text-align: center">
<td style="text-align: left">
<asp:Button ID="btnWEFCLOSE" runat="server"
Text="CLOSE"
CausesValidation="false" Font-Bold="True" Width="61px" />
</td>
</tr>
</table>
</div>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</td></tr></table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
The major point of the code above is that I have a very deep GridView inside an UpdatePanel that's inside a ModalPopUp.
Now look at what I have inside that GridView:
OnPageIndexChanging
and
OnSorted
Inside the GridView, there is another ModalPopup and TextBox. Ignore that. That's only so the user can see the comments from the student's contact log as another popup window.
So if we now go to the code behind for the above two events:
protected void gvWEFContactLog_Sorted(object sender, EventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
protected void gvWEFContactLog_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvWEFCL = (GridView)sender;
GridViewRow gvRow = (GridViewRow)gvWEFCL.NamingContainer;
UpdatePanel upWEF1 = (UpdatePanel)gvRow.FindControl("upWEF1");
if (upWEF1 != null) upWEF1.Update();
AjaxControlToolkit.ModalPopupExtender mpeWEF = (AjaxControlToolkit.ModalPopupExtender)gvRow.FindControl("mpeWEF");
if (mpeWEF != null) mpeWEF.Show();
}
Notice that I am not actually controlling the sorting or the paging itself. I am only forcing the GridView to call upon the main UpdatePanel (upWEF1) to refresh itself via an Update() call. The next step is to grab the ModalPopup I want to keep visible and re-Show() it!
And that's all there is to it!
I am sure there is a cleaner solution using JavaScript itself, but for me this avoids that dread meaningless error and I have a clean set of popups and update panels that can handle both hotlinks, sorting and paging as I want the GridView to perform!
I've been reading a few posts in here and some are related to my problem, but for some reason the solutions provided dont work for me. Basically I have two GridView controls with checkboxes. They have the exact same code, but just fire different events. And of course have different IDs and their pertinent unique information. Here is the weird thing, one of them works just fine, and the other one doesn't. I will post both here, keep in mind that the one with ID="UnassignElegibilityChk" is the onte that is not working. I've put breakpoints to test whether I am inside the function when I send the postback from the check and nothing.
Note: both of these treeviews are on the same page, so please assume the codebehind directive and all the settings are properly assigned to the page (since one of them is working i would assume there is no problem with that)
This is the one that is not working:
<table><tr><td class="style1">
<asp:GridView ID="ElegibilitySelectedGridview" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID" CellPadding="4"
ForeColor="#333333" GridLines="None" Width="475px">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblID0" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="UnassignElegibilityChk" runat="server" AutoPostBack="true" OnCheckedChanged="UnAssignElegibilityRecord"/>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="Name" HeaderText="Elegible Item" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</td></tr></table>
The one that is working is below:
<table><tr><td class="style1">
<asp:DropDownList ID="ElegibilityGroupDDL" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ElegibilityGroupDDL_SelectedIndexChanged">
<asp:ListItem Value="0">ROOT</asp:ListItem>
</asp:DropDownList>
</td></tr><tr><td class="style1">
<asp:TextBox ID="ElegibilityNameTxt" runat="server" Width="464px"></asp:TextBox>
</td></tr><tr><td class="style1">
<asp:Button ID="ElegibilitySaveBtn" runat="server" Text="Save Elegibility" />
</td></tr><tr><td class="style1">
<asp:Label ID="ElegibilityMsgLbl" runat="server" Text="" style="color: #0066CC"></asp:Label>
</td></tr><tr style="background:silver"><td class="style1">
</td></tr><tr><td class="style1">
<asp:GridView ID="ElegibilityGridView" runat="server"
AutoGenerateColumns="False" DataKeyNames="ID" BackColor="White"
BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4"
ForeColor="Black" GridLines="Vertical" Width="95%">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="AssignElegibilityChk" runat="server" AutoPostBack="true" OnCheckedChanged="AssignElegibility"/>
</ItemTemplate>
</asp:TemplateField>
<asp:boundfield datafield="Name" HeaderText="Elegible Item" />
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
</td></tr></table>
The working gridview fires this function successfully:
Public Sub AssignElegibility()
If Page.IsPostBack Then
For Each row As GridViewRow In ElegibilityGridView.Rows
Dim checkbox As CheckBox = CType(row.FindControl("AssignElegibilityChk"), CheckBox)
'Check if the checkbox is checked.'
'value in the HtmlInputCheckBox Value property is set as the //value of the delete commands parameter.'
If checkbox.Checked Then
' Retreive the Employee ID'
Dim lblID As Label = CType(row.FindControl("lblID"), Label)
Dim elegibilityID As Integer = Convert.ToInt32(lblID.Text)
Elegibility.AddElegibilityMapping(CInt(Request("ResID")), elegibilityID)
ElegibilitySelectedItems(CInt(Request("ResID")))
ElegibilityGroupDDL_SelectedIndexChanged()
End If
Next
End If
End Sub
The non working one is supposed to fire this code and it isn't.
Public Sub UnAssignElegibilityRecord(ByVal sender As Object, ByVal e As System.EventArgs)
PrintLine("Inside the sub")
If Page.IsPostBack Then
For Each row As GridViewRow In ElegibilitySelectedGridview.Rows
Dim checkbox As CheckBox = CType(row.FindControl("UnassignElegibilityChk"), CheckBox)
'Check if the checkbox is checked.'
'value in the HtmlInputCheckBox Value property is set as the //value of the delete commands parameter.'
If checkbox.Checked Then
' Retreive the Employee ID'
Dim lblID As Label = CType(row.FindControl("lblID0"), Label)
Dim elegibilityID As Integer = Convert.ToInt32(lblID.Text)
Elegibility.RemoveElegibilityMapping(elegibilityID)
ElegibilitySelectedItems(CInt(Request("ResID")))
ElegibilityGroupDDL_SelectedIndexChanged()
End If
Next
End If
End Sub
I don't know if anything of the following solves your problem, but ...
why does your "working" handler of the CheckedChanged has the wrong signature? It needs the sender and the eventsargs.
protected Sub AssignElegibility(ByVal sender As Object, ByVal e As System.EventArgs)
Why do you iterate the Gridrows to get the Checkbox and the row that has changed? This works also:
Dim checkbox As CheckBox = DirectCast(sender,CheckBox)
To get the Row you only have to cast the NamingContainer of your Checkbox to GridViewRow.
Dim row as GridViewRow =DirectCast(checkbox.NamingContainer,GridViewRow)
EDIT: Do you rebind the ElegibilitySelectedGridview-Grid on Postback?
You should only do that when not Page.IsPostback, otherwise events won't fire.
Hi
I'm new to ajax.
I'm working on visual studio 2005. I install the ajax Min4setup and I add the control toolkit to the controls toolbar.
I created a new website Ajax-Enabled then I add the existing items (all the page) from the old web site to the new one.
I wrote the code below in the page.aspx and the other code in page.aspx.vb but nothing happens, the timer event is not firing.
Code:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="8000" Enabled="true">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="test" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" Width="616px" BorderStyle="Outset">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="Sender" HeaderText="Sender"
SortExpression="MO_NICKNAME_SOURCE_LOG_HIS" />
<asp:BoundField DataField="DataChat" HeaderText="Conversation" SortExpression="DataChat" />
<asp:TemplateField HeaderText="Date" SortExpression="DATETIMEIN_LOG_HIS">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("DATETIMEIN_LOG_HIS") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("DATETIMEIN_LOG_HIS") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OfflineChat_ConnectionString %>"
SelectCommand="SP_GET_OFFLINE_USER_CHAT" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="MO_OFFLINEUSER" SessionField="ID" Type="String" />
<asp:QueryStringParameter Name="MO_NICKNAME_REALUSER" QueryStringField="realuserNick"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs)
{
Label1.Text = "Grid Refreshed at: "
'& DateTime.Now.ToString
GridView1.DataBind()
UpdatePanel1.Update();
}
Any idea or suggestion will be highly appreciated.
Best Regards,
Start the timer with timer1.Start().
Clear the GridView, set GridView1.DataSet = null and reload the Bindings.