ASP.NET Bootstrap 4 Pagination - c#

I used pagination as described in this article
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass='<%# Convert.ToBoolean(Eval("Enabled")) ? "page_enabled" : "page_disabled" %>'
OnClick="Page_Changed" OnClientClick='<%# !Convert.ToBoolean(Eval("Enabled")) ? "return false;" : "" %>'></asp:LinkButton>
</ItemTemplate></asp:Repeater>
This is link to Demo
I want to customize the pagination style by using bootstrap 4 pagination class
This is what i did but the current page is not highlighted
<ul class="pagination"> <asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<li class="page-item">
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass="page-link"
OnClick="Page_Changed" OnClientClick='<%# !Convert.ToBoolean(Eval("Enabled")) ? "return false;" : "" %>'></asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater></ul>
How can i use BOTH CssClass="page-link" AND CssClass='<%# Convert.ToBoolean(Eval("Enabled")) ? "active" : "disabled" %>'

You can combine more classes by separating them by space. Example below.
<ul class="pagination">
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass='<%# Convert.ToBoolean(Eval("Enabled")) ? "active page-link" : "disabled page-link" %>'
OnClick="Page_Changed" OnClientClick='<%# !Convert.ToBoolean(Eval("Enabled")) ? "return false;" : "" %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
</ul>

Related

How can i use If condition in aspx page for image url?

My dataset return this table link.How can i use If else conditons in aspx page?I want if the File_path is Null or empty then image not show because if File_Path is empty then it give me error,I want if File_Path is not empty then image will be show.Following error
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Here is my code
<asp:DataList ID="DataList2" runat="server" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center" RepeatLayout="Table">
<ItemTemplate>
<div class="<%#GetStyleForMsgList(Eval("MsgSender").ToString()) %> MainChatListClass">
<asp:Label ID="Label1" runat="server" Text='<%# GetPerfactName(Eval("MsgSender").ToString()) %>'></asp:Label>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("ChatMsg") %>'></asp:Label>
<asp:Label ID="lblfile" runat="server" Visible ="false" Text='<%# Eval("File_Path") %>'></asp:Label>
<% if (Eval("File_Path") != null)
{%>
<asp:Image ID ="img" runat ="server" ImageUrl ='<%# Eval("File_Path") %>' />
<% } %>
</div>
</ItemTemplate>
</asp:DataList>

Why Rowcommand event of a gridview is not getting fired ?

I am facing a kind of weird problem.
Problem:
When I click a link button inside a grid view then RowCommand event of a grid view is getting fired when deployed on a localhost but not when deployed on the IIS i.e. client system. I have also tried a link button inside grid view but that's also not getting fired.
Solution: (Temporary)
When I disabled ValidateRequest on the top of the .aspx page. It worked.
What should I do?
So what can be the possible solution for it? I have googled but nothing good came up.
Code:
<asp:GridView ID="gvAppliedWorks" runat="server" OnRowCommand="gvAppliedWorks_RowCommand" AutoGenerateColumns="false" DataKeyNames="AppliedWorkID, ContractorID" EmptyDataText="No Data Found"
CssClass="table table-responsive table-bordered table-striped" OnRowDataBound="gvAppliedWorks_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Form No">
<ItemTemplate>
<asp:Literal ID="liFormNo" runat="server" Text='<% #Eval("FormNo")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Company Name">
<ItemTemplate>
<asp:Literal ID="liCompanyName" runat="server" Text='<% #Eval("Name")%>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Financial Bid">
<ItemTemplate>
<asp:Label ID="txtBidAmount" runat="server" CssClass="control-label" Text='<% # string.Format("{0:n2}", Eval("FinancialMoney").ToString())%>' />
%
<asp:Label ID="ddlBidPer" runat="server" CssClass="control-label" Text='<%# Eval("AboveBelow").ToString() %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Awarded Percentage">
<ItemTemplate>
<div class="pull-left">
<asp:HiddenField ID="hdnIsAwarded" Value='<%# Eval("IsAwarded") %>' runat="server" />
<asp:TextBox ID="txtAwardedBid" Text='<%#Eval("AwardedBid")%>' Style="width: 70px !important;" runat="server" CssClass="form-control"></asp:TextBox>
</div>
<div class="pull-left" style="margin-top: 7px">
% <%# Eval("AboveBelow").ToString() %>
</div>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Remarks">
<ItemTemplate>
<asp:TextBox ID="txtRemarks" Text='<%#Eval("Remarks")%>' runat="server" CssClass="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Award Tender">
<ItemTemplate>
<asp:LinkButton ID="lnkAward" runat="server"
CommandArgument='<%# Eval("AppliedWorkID") %>' CommandName="award"
CssClass="btn btn-sm btn-danger" Enabled='<%# Convert.ToBoolean(Eval("IsBlackList")) == true ? false: true %>'
Visible='<%# Convert.ToBoolean( Eval("IsAwarded"))== false? true:false%>' CausesValidation="false" Text="Award"></asp:LinkButton>
<ajax:ConfirmButtonExtender ID="cbe" runat="server" DisplayModalPopupID="mpe" TargetControlID="lnkAward">
</ajax:ConfirmButtonExtender>
<ajax:ModalPopupExtender ID="mpe" runat="server" PopupControlID="pnlPopup" TargetControlID="lnkAward" OkControlID="btnYes"
CancelControlID="btnNo" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlPopup" runat="server" CssClass="modalPopup" Style="display: none">
<div class="header">
Confirmation
</div>
<div class="body">
Are you sure to Award this Work?
</div>
<div class="Popupfooter" align="right">
<asp:Button ID="btnYes" CssClass="btn btn-sm btn-danger" runat="server" Text="Yes" />
<asp:Button ID="btnNo" CssClass="btn btn-sm btn-primary" runat="server" Text="No" />
</div>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText='Action'>
<ItemTemplate>
<asp:LinkButton ID="btnBlackList" runat="server" OnClick="btnBlackList_Click" Visible='<%# Convert.ToBoolean( Eval("IsAwarded"))== false? true:false%>' Enabled='<%# Convert.ToBoolean(Eval("IsBlackList")) == true ? false: true %>' Text='Defective'
CssClass="" ToolTip="Blacklist"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
**.cs**
protected void gvAppliedWorks_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
// GridViewRow gr = ((GridViewRow)((Control)sender).Parent.Parent);
if (e.CommandName == "award")
{
GridViewRow gr = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
int AppliedWorkID = e.CommandArgument.ToInt32(); //gvAppliedWorks.DataKeys[gr.RowIndex].Value.ToInt32();
TextBox txtAwardedBid = gr.FindControl("txtAwardedBid") as TextBox;
TextBox txtRemarks = gr.FindControl("txtRemarks") as TextBox;
Label txtBid = gr.FindControl("txtBidAmount") as Label;
Label lblAboveBelow = gr.FindControl("ddlBidPer") as Label;
string AboveBelow = lblAboveBelow.Text;
Decimal BidAmount = txtBid.Text.ToDecimal();
if (String.IsNullOrEmpty(txtRemarks.Text))
{
Utility.Msg_Error(this.Master, "Remarks Required!!!");
return;
}
Decimal AwardedBid = string.IsNullOrEmpty(txtAwardedBid.Text.Trim()) ? 0 : txtAwardedBid.Text.Trim().ToDecimal();
string Remarks = txtRemarks.Text;
if (AwardedBid != BidAmount)
{
Utility.Msg_Error(this.Master, "Financial Bid must be equal to Awarded Percentage");
return;
}
if (ClsTender.IsReceivedSubMainOffice(AppliedWorkID, LoginUserID, AwardedBid, Remarks, BidAmount, AboveBelow))
{
Utility.Msg_Success(this.Master, "Work Awarded Successfully!!!");
fill_gvAppliedWorks(labNitNo.Text.Replace("NIT No :", "").ToInt32(), labWorkNo.Text.Replace("Work No :", "").ToInt32());
}
}
}
catch (Exception ex)
{
Utility.Msg_Error(Master, ex.Message);
}
}
It sounds like your page is trying to submit what it thinks is potentially dangerous content if setting the ValidateRequest = false solves the issue. Is it possible that one of the controls on your page is sending html or something like that?
If one of your controls needs to send HTML then you can overcome this by adding an attribute to your model.
[AllowHtml]
[Required]
public string article_content { get; set; }
This will allow html to be entered into the control.

Specified cast not valid error shows on aspx gridView

I get this error on this column in a `gridview' :-
<asp:TemplateField>
<ItemTemplate>
<%# Eval("title") %>
<br />
<p runat="server" id="description"><%# Eval("des") %></p>
<asp:ImageButton ID="click_like" runat="server" ImageUrl= "~/pics/like.png" Height="20px" CommandName="like" CommandArgument='<%# Eval("id") %>' BorderStyle="Outset" BorderColor="#99CCFF" Enabled='<%# Eval("like_enabled") %>' />
<asp:Label ID="lbl_like" runat="server" Text='<%# Eval("like") %>'></asp:Label>
<asp:ImageButton ID="click_dislike" runat="server" ImageUrl="~/pics/dislike.png" Height="20px" CommandName="dislike" CommandArgument='<%# Eval("id") %>' BorderStyle="Outset" BorderColor="#99CCFF" Enabled='<%# Eval("dislike_enabled") %>'/>
<asp:Label ID="lbl_dislike" runat="server" Text='<%# Eval("dislike") %>'></asp:Label>
<p runat="server" id="labels"><%# Eval("labels") %></p>
</ItemTemplate>
</asp:TemplateField>
I get this error on the line:-
<asp:ImageButton ID="click_like" runat="server" ImageUrl= "~/pics/like.png" Height="20px" CommandName="like" CommandArgument='<%# Eval("id") %>' BorderStyle="Outset" BorderColor="#99CCFF" Enabled='<%# Eval("like_enabled") %>' />
And I get this because I am binding the value of Enabled attribute from a DataTable where like_enabled column is either "true" or "false"
You're not able to bind Enabled like that, you'll have to use an RowDataBound event:
<asp:GridView id="myGrid" OnRowDataBound="myGrid_RowDatabound">
Code behind:
public void myGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
var enabled = (bool)DataBinder.Eval(e.Row.DataItem, "like_enabled");
var click_like = e.Row.FindControl("click_like") as ImageButton;
click_like.Enabled = enabled;
}
}

Change link button color in Repeater

I am using Data Repeater and Link Button inside repeater . I want to change the color of clicked button but it is not working . Here is my code.
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton Font-Size="Larger" BackColor="Orange" ForeColor="White" ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
CssClass=" btn"
OnClick="Page_Changed"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
protected void Page_Changed(object sender, EventArgs e)
{
int pageIndex = int.Parse((sender as LinkButton).CommandArgument);
LinkButton lnk = (LinkButton)sender;
lnk.ForeColor = System.Drawing.Color.Red;
lnk.BackColor = System.Drawing.Color.Red;
this.GetImagesPageWise(pageIndex);
}
Do this way. Create class for Current Page LinkButton
.Active
{
color:red;
font:bold 12px Tahoma;
}
Then Change the Repeater as following
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
Enabled='<%# Eval("Enabled") %>' OnClick="Page_Changed" CssClass='<%# Convert.ToBoolean(Eval("Enabled")) == true ? "LBR" : "Active" %>'></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
<ul class="pagination">
<asp:Repeater ID="rptPager" runat="server">
<ItemTemplate>
<li class="<%#GetStatus(Eval("Enabled").ToString(),Eval("Text").ToString())%>">
<asp:LinkButton ID="lnkPage" runat="server" Text='<%#Eval("Text") %>' CommandArgument='<%# Eval("Value") %>'
Enabled='<%# Eval("Enabled") %>' OnClick="Page_Changed">
</asp:LinkButton>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
Protected Function GetStatus(ByVal Enable As Boolean, ByVal linkName As String) As String
Try
If Enable = 0 And linkName <> "First" And linkName <> "Last" Then
Return "active"
Else
Return ""
End If
Catch ex As Exception
Return ""
End Try
End Function

Add Repeater items to Listbox

I have a Repeater which contains Eval commands and a Button (Which I can't access) I would like to access this button and when clicked insert one of the Eval commands (Eg. Car Model) into a listbox I have on the same page.
<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />
<asp:Repeater ID="Repeater2" runat="server" DataSourceID="AccessDataSource1" DataMember="DefaultView" OnItemDataBound="Repeater2_ItemDataBound">
<ItemTemplate>
<div>
<p><img src="carImages/<%#Eval("Artwork")%>" /></div>
<div class="col-xs-4">
<h4><%# Eval("Make")%> (<%# Eval("Year") %>)</h4>
<p><%# Eval("Model")%></p>
<p><%# Eval("Colour")%></p>
<p><%# Eval("Type")%></p>
<div>
<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />
</div>
</a>
</div>
</ItemTemplate>
Just add your oncommand argument to the repeated button
<asp:Button ID="modelButton" CommandArgument='<%# Eval("Model") %>' OnCommand="CommandBtn_Click" Text='<%# "Add Model to List:" + Eval("Model") %>' runat="server" />
you can grab the eval in the behind code
void CommandBtn_Click(Object sender, CommandEventArgs e){
var command = e.CommandArgument;
// Do whatever with it here
}
That will get the evaluated model

Categories

Resources