Display table content using querystring - c#

I have one page in asp, contain three table ( Pending order, confirmed order and rejected order). This three table under one header. When user click on pending order word on header, page will display only pending table. This three information in on code page using asp. How can get this function work using the query string?
Detail:
As refer image below, current state all the information in one page,
The request is when user click on the pending order, it only display the pending table, also apply to confirm and rejected.
Each table using grid view function and i want to use the query string. If I use to create separate page for this,it will involve to many definition.
Update the code:
The code for the every table i use grid view in the aspx file.
<div class="col-md-12 account-title">
Your Pending Orders Confirmation
</div>
<div class="col-md-12 col-sm-12 table-responsive">
<asp:GridView ID="grdvwPendingOrder" ShowFooter="false" AutoGenerateColumns="False" runat="server" CssClass="table table-bordered text-center"
OnRowCommand="grdvwPendingOrder_RowCommand" OnRowDataBound="grdvwPendingOrder_RowDataBound" EmptyDataRowStyle-ForeColor="Red"
EmptyDataRowStyle-BackColor="White" EmptyDataText="No Records Found">
<HeaderStyle CssClass="table-title text-center" />
<RowStyle CssClass="account-content text-center" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>Order No.</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblOrderNo" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Date</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OrderDate", "{0:dd/MM/yyyy}") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Placed By</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPlacedby" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "CustomerName") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Status</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OrderStatus") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Actions</HeaderTemplate>
<ItemTemplate>
<asp:Button ID="btnReview" runat="server" CssClass="btn btn-success" Text="Review" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Id") %>' CommandName="Review" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<!-- Pagination -->
<div class="col-md-12 col-sm-12 col-xs-12 padLROff">
<ucPageControl:PageControl ID="PendingOrderPageControl" Title="" runat="server" Visible="false" />
</div>
Code for pending order.
The confirmed and rejected in the same file.
Now I want to build a header for this type as table above. As mention, if i separate the type to different aspx file, it will involve to many definition.

Related

Failed to Load Viewstate Error after editing Gridview in ModalPopupExtender

I am getting the following error.
HttpStatusCode:500
Name:Sys.WebForms.PageRequestManagerServerErrorException
Message: Sys.WebForms.Page.RequestManagerServerErrorException
Failed to Load viewstate. The control tree into which viewstate is being
loaded must match the control tree that was used to save viewstate during
the previous request.
The scenario is as follows I have a Gridview that is bound after a DropDownList is selected. Then you can click a row on the Gridview and a ModalPopupExtender pops up. There is another GridView in the popup. If I edit that Gridview and then exit the ModalPopupExtender, and then select a different value on the DropDownList which generates the original Gridview I get the error.
DropDownList
<asp:DropDownList ID="SearchCategoryDD" runat="server" DataSourceID="InductionCategoriesDS" DataTextField="CompentencyCategory" DataValueField="CompentencyCategoryID" AutoPostBack="True" OnDataBound="SearchCategoryDD_DataBound" OnSelectedIndexChanged="SearchCategoryDD_SelectedIndexChanged"></asp:DropDownList>
Gridview when Databound with new data causes error
<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
<asp:GridView runat="server" ID="SkillsXXX" OnRowDataBound="SkillsXXX_OnRowDataBound" >
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:LinkButton runat="server" ID="SelectLBXX" Visible="False" OnClick="SelectLBXX_OnClick"></asp:LinkButton>
<asp:Label runat="server" ID="EmployeeXXXXD" Text='<%# Bind("EmployeeID") %>' Visible="False"></asp:Label>
</EditItemTemplate>
......
...
ModalPopupExtender with Gridview
<asp:Button ID="EditSupplierContactPopupBTN" runat="server" Text="" Style="visibility: hidden;" />
<ajaxToolkit:ModalPopupExtender ID="EditSupplierContactMPE" runat="server" CancelControlID="EditSupplierContactCancelBTN"
TargetControlID="EditSupplierContactPopupBTN" PopupControlID="EditSupplierContactPanel" PopupDragHandleControlID="EditSupplierContactHeader"
Drag="true" BackgroundCssClass="ModalPopupBG">
</ajaxToolkit:ModalPopupExtender>
<asp:Panel ID="EditSupplierContactPanel" runat="server" CssClass="PopupPNL" Style="display: none"> <!-- Style="display: none" -->
<div class="PopupHeader" id="EditSupplierContactHeader">
<div class="PopupControls">
<asp:Button ID="EditSupplierContactCancelBTN" runat="server" Text="Close" />
</div>
Edit Truck Driver
</div>
<div class="PopupBody">
<asp:UpdatePanel ID="UpdatePanel3" runat="server"><ContentTemplate>
<asp:GridView ID="Competancies2GV" runat="server" AutoGenerateColumns="False" DataKeyNames="SkillsMatrixID" Width="100%">
<Columns>
<asp:TemplateField InsertVisible="False" SortExpression="SkillsMatrixID">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("SkillsMatrixID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="EditSkillsMatrixLB" runat="server" CommandArgument='<%# Eval("SkillsMatrixID") %>' OnCommand="EditSkillsMatrixLB2_Command">Edit</asp:LinkButton>
<asp:HiddenField runat="server" ID="SkillsMatrixIDHF" Value='<%# Bind("SkillsMatrixID") %>'/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CompentencyCategory" HeaderText="Category" SortExpression="CompentencyCategory">
</asp:BoundField>
<asp:BoundField DataField="CompentencyName" HeaderText="Compentency" SortExpression="CompentencyName">
</asp:BoundField>
...........
........
.....
I have tried the loading the Datatable from ViewState in the LoadViewState method. I still get the error.
LoadViewState
protected override void LoadViewState(object earlierState)
{
base.LoadViewState(earlierState);
dataTable = (DataTable)ViewState["dataTable2"];
SkillsMatrixGV.DataSource = dataTable;
compentencyDataTable = (DataTable) ViewState["CompentencyDataTable2"];
Competancies2GV.DataSource = compentencyDataTable;
Competancies2GV.DataBind();
......
...
if I put EnableViewState="false" into the page or the GridView the error goes away but my GridView in the ModalPopupExtender does not update.

Failed to load resource: the server responded with a status of 404 (Not Found) in Asp.NET GridView

I am trying to load images from the folder UploadImages combined with image name for the particular query
my gridview code is as follows:
<asp:GridView ID="gvDetails" runat="server" AllowPaging="false" PageSize="50" ShowHeader="false" GridLines="None" AutoGenerateColumns="false" Width="100%" OnPageIndexChanging="gvDetails_PageIndexChanging">
<PagerSettings Mode="NumericFirstLast" PageButtonCount="4" FirstPageText="First" LastPageText="Last" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<h2><asp:Label runat="server"><%#Eval("Ads_Title")%></asp:Label></h2>
<h5><asp:Label runat="server" Text='<%#Eval("Ads_Posted_Date")%>'></asp:Label>, Posted by <asp:Label runat="server" Text='<%#Eval("Ads_State")%>'></asp:Label></a></h5>
<div class="blog-para">
<p class="para">
<image src='../UploadImages/<%#Eval("Busines_Image") %>' Width="150px" />
<p><asp:Label runat="server" Text='<%#Eval("Cat_Name")%>'></asp:Label></p>
<p>Pokect Listing: <asp:Label runat="server" Text='<%#Eval("PocketListing")%>' /> </p>
<p><asp:Label Text='<%# Eval("Ads_Hot_Normal") == "false" ? "<image src='images/premium_logo.png' alt='Premium'" : " " %>'runat="server" /></p>
<div class="read_more">
<a class="btn" href='AdsDetails.aspx?AddId=<%#Eval("main_ID") %>'>Read More</a>
</div>
</p>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Every time i run the webapp it states faied to load the resource.
This is might be happening because GridView control is losing View. For more details yo can try this Link

ASP.NET repeater get all items and checkbox if user has right

I have an ASP.NET application and I would like to display all roles and add a checkbox which is checked if the user has the right.
I use an ASP repeater to get all roles but how can I check the checkbox in the same repeater to get the user's role ?
Here is my code:
<asp:Repeater ID="RepeaterRole" runat="server" DataSourceID="ObjectDataSource2">
<ItemTemplate>
<div>
<asp:CheckBox runat="server" Checked="False" />
<asp:Label CssClass="lbl" ID="Label1" runat="server" Text='<%# Eval("RoleLabel")%>'></asp:Label>
</div>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetAllRolesToCollection" TypeName="Business.BusinessObject.Role"></asp:ObjectDataSource>
<asp:Repeater ID="RepeaterRole" runat="server" DataSourceID="ObjectDataSource2">
<ItemTemplate>
<div>
<asp:CheckBox runat="server" Checked='<%# Convert.ToBoolean(Eval("role")) %>' />
<asp:Label CssClass="lbl" ID="Label1" runat="server" Text='<%# Eval("RoleLabel")%>'></asp:Label>
</div>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetAllRolesToCollection" TypeName="Business.BusinessObject.Role"></asp:ObjectDataSource>
Make sure you get 'role' field 1 or 0 from DB
Thanks Hardik,
based on your solution, I created a similar method like this: public Dictionary GetAllRolesFromUserToDictionary() so the checkbox will bind to the boolean value
Then the ASP code is like this:
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource3">
<ItemTemplate>
<div>
<asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Eval("Value")%>' />
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Key")%>'></asp:Label>
</div>
</ItemTemplate>
</asp:Repeater>
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server" SelectMethod="GetAllRolesFromCurrentUserToDictionary" TypeName="BusinessObject.RoleCollection"></asp:ObjectDataSource>

Open prettyPhoto popup with aspx page inside on GridView button click

At the moment I have an aspx page with a gridview on it. I would like to add a prettyPhoto popup which appears on a button click within the gridview. The popup will have details of the selected row. My gridview looks like this:
<asp:GridView ID="gvBacklog" runat="server" AutoGenerateColumns="false" DataKeyNames="BacklogID" CssClass="table table-striped table-bordered table-condensed table-responsive" DataSourceID="ldsBacklog" AllowPaging="true" AllowSorting="true">
<Columns>
<asp:BoundField DataField="BacklogID" HeaderText="Backlog ID" SortExpression="BacklogID" />
<asp:TemplateField HeaderText="User Story" SortExpression="Story.StoryName">
<ItemTemplate>
<%#Eval("Story.StoryName") %>
</ItemTemplate>
<EditItemTemplate>
<itemtemplate>
<asp:TextBox Id="txtStoryName" runat="server" Text='<%#Bind("Story.StoryName")%>'></asp:TextBox>
</itemtemplate>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" SortExpression="Story.StoryDesc">
<ItemTemplate>
<%#Eval ("Story.StoryDesc") %>
</ItemTemplate>
<EditItemTemplate>
<itemtemplate>
<asp:TextBox Id="txtDesc" runat="server" Text='<%#Bind("Story.StoryDesc")%>'></asp:TextBox>
</itemtemplate>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Story Points" SortExpression="Story.StoryPoints">
<ItemTemplate>
<%#Eval ("Story.StoryPoints") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlFibbonacci" runat="server" SelectedValue='<%#Bind("Story.StoryPoints")%>'>
<asp:ListItem>0</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>13</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
<asp:ListItem>40</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Size" SortExpression="Story.Size">
<ItemTemplate>
<%#Eval ("Story.Size") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="WSJF Score" SortExpression="Story.WSJFScore">
<ItemTemplate>
<%#Eval ("Story.WSJFScore") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sprint" SortExpression="Sprint.SprintNumber">
<ItemTemplate>
<%#Eval("Sprint.SprintNumber") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlSprint" DataSourceID="ldsSprint" DataValueField="SprintNumber" SelectedValue='<%#Bind("Sprint.SprintNumber") %>' runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Added By" SortExpression="User.Username">
<ItemTemplate>
<%#Eval ("User.Username") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbEdit" runat="server" CssClass="btn btn-default">
<span class="glyphicon glyphicon-pencil"></span>
</asp:LinkButton>
<asp:LinkButton ID="lbDelete" runat="server" CssClass="btn btn-default" CommandName="Delete">
<span class="glyphicon glyphicon-remove"></span>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Any tips or advice would be really helpful! I've looked online and can't seem to find anything.
Performing a popup from a gridview is a tricky business. The act of Selecting a row causes a postback which plays havoc with trying to manage the Client side popup code. You have to do some hoop jumping to make the popup appear after the postback completes. But causing a postback kind of defeats the purpose of using a popup to begin with.
So one way to handle this is to make sure all the detail information is available on the initial pass. You can do this by embedding a DetailsView (with it's own datasource that is populated with the key from the current row) in a hidden div embedded in an new or existing template field in the current GridView.
Or, if you are ok with the postback, just throw a hidden div containing the DetailsView on the current page below everything else and just work out the logic to display the now populated DV after post completes.
I used a Bootstrap modal to implement the functionality.
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>One fine body…</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
$('#exampleModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
})

user control inside dynamic user control click event not firing?

I have a page where there is a div, for which the user controls are added dynamically through the code using the LoadControl of user control.
The user control contains another user control (lets say ChildUC).
The ChildUC contains a gridview which has Insert and Delete buttons.
The problem is, even though I click on these buttons, the click event is not getting fired nor the gridview command event.
The page is being postbacked and just exits after the page load, it is not firing any other events.
I am debugging this for last few days so far, but of no luck.
Please do help me. Thanks in Advance.
Code:
<div id="dvMain" runat="server">
</div>
private void CreateHeaders()
{
foreach (Header hd in HeaderCollection)
{
List<Question> lstQuestion = QuestionCollection.FindAll(p => p.HID.Equals(hd.HeaderID));
Sales_UserControls_Questions Question = null;
if (lstQuestion.Count > 0)
{
Question = (Sales_UserControls_Questions)LoadControl("~/Sales/UserControls/Questions.ascx"); // This is the main user control that is being loaded dynamically
Question.ID = "Question"+hd.HID;
Question.lstQuestions = lstQuestion;
}
dvMain.Controls.Add(Header);
if (HQQuestion != null)
dvMain.Controls.Add(Question); // user control being added to div
}
}
//Questions.ascx
<div>
<asp:GridView ID="grdContent" runat="server" AutoGenerateColumns="False"
OnRowDataBound="grdContent_RowDataBound" EnableTheming="False">
<Columns>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:HiddenField ID="hdnQuestionID" runat="server" Value='<%# Eval("QID") %>' />
<asp:HiddenField ID="hdnQuestionType" runat="server" Value='<%# Eval("QTP") %>' />
<asp:Label ID="lblQuestionID" runat="server" EnableTheming="False" Text='<%# Eval("QID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
<asp:Label ID="lblSHR" runat="server"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblText" runat="server" Text='<%# Eval("Text") %>'></asp:Label>
<div>
<asp:UpdatePanel ID="UpnlDGV" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<DG:View ID="ucDGView" runat="server"></DG:View>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
//end of questions.ascx
//ucDGView.ascx
<div>
<asp:GridView ID="grdDGView" runat="server"
AutoGenerateColumns="False" OnRowDataBound="grdDGView_RowDataBound" OnRowDeleting="grdDGView_RowDeleting"
OnRowCreated="grdDGView_RowCreated" HeaderStyle-Font-Bold="true" OnRowCommand="grdDGView_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<dl id="dvNT" runat="server">
<dt>
<asp:Label ID="lblNT" runat="server" Text="NT:"></asp:Label>
</dt>
<dd>
<asp:DropDownList ID="ddlNM" runat="server">
</asp:DropDownList>
</dd>
</dl>
<dl id="dvOSD" runat="server" class="grid_6 alpha MT10" visible="false">
<dt>
<asp:Label ID="lblOSDT" runat="server" Text="OSDT:"></asp:Label>
</dt>
<dd>
<asp:TextBox ID="txtOSDT" runat="server" MaxLength="10" CssClass="maskDate"></asp:TextBox>
<asp:CalendarExtender ID="txtOSDTE" runat="server" TargetControlID="txtOSDT"
Enabled="True" Format="MM/dd/yyyy">
</asp:CalendarExtender>
</dd>
</dl>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgBtnDelete" runat="server" ImageUrl="~/Sales/Common/Images/delete_red_mini.jpg"
CausesValidation="false" CssClass="cancel" CommandName="Delete" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "OID")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgBtnAdd" runat="server" ImageUrl="~/Sales/Common/Images/PLUS_MINI.png"
CausesValidation="false" CssClass="cancel" CommandName="Add" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "QID")%>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
//end of ucDGView.ascx
What you need to understand here is where in the asp.net page life cycle does it receive the event from the frontend.
The event that triggers the postback is sent back to asp.net is a hidden form element called the event target.
This input is processed in in a function called the ProcessPostData.
If your control is not present in the controls collection by then, it cannot receive the event. So you get a postback, but no event handlers are fired.
That means, if you want your event handlers to fire, you must create all your controls before the load event. It seems you have to decide which controls to load depending upon some user input. User inputs are not available on Init. You can override the LoadViewState method, and process your user input there.

Categories