My codes are
<asp:LinkButton ID="LinkButton1" runat="server"
PostBackUrl='<%# String.Format("~/WebForms/AnaEkran_EPDK.aspx?id={0}", Eval("ID")) %>' >
</asp:LinkButton>
and
<a href="~/WebForms/AnaEkran_Bayi.aspx?id=<%# Eval("ID") %>" >.....</a>
and they don't work. On the linkbutton output is a javascript:__doPostBack('LinkButton1', ''), why doesn't id take?
go for OnClientClick of link button
from code behind
put this in page load
LinkButton1.OnClientClick = "window.location = '~/WebForms/AnaEkran_EPDK.aspx?id="+ ID.toString() + "'; return false;"
Or in aspx do this
<asp:LinkButton ID="LinkButton1" runat="server"
OnClientClick="goToYourPage();" >
</asp:LinkButton>
Try adding this attribute to your LinkButton:
href='<%#"~/WebForms/AnaEkran_Bayi.aspx?id="+Eval("ID")%>'
Related
Hi I have the following TextBox:
<asp:TemplateField HeaderText="Email">
<EditItemTemplate>
<asp:TextBox ID="txt_email" runat="server" Text='<%#Eval("usr_email") %>' class="custom-table-text"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
If I need to get Eval\db value I can simply do either:
<asp:LinkButton.... OnClientClick='<%# "ValidateEmail(\"" + Eval("usr_email") + "\"); return false;" %>'
<asp:LinkButton.... OnClientClick='<%# "ValidateEmail(\"" + DataBinder.Eval(Container.DataItem, "usr_email") + "\"); return false;" %>'
But how to get the value of current textbox (current row):
inside LinkButton OnClientClick.
before postback (client-side\without postback\not in code-behind).
I found it in case anyone finds it useful or has any comment:
OnClientClick='<%# String.Format("return ValidateEmail({0}.value)", (((GridViewRow)Container).FindControl("txt_email") as TextBox).ClientID) %>'
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>
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
I have a webform that contains a listview like this:
<asp:ListView ID="SlidesListView" runat="server" OnItemCommand="SlidesListView_ItemCommand">
<LayoutTemplate>
<span runat="server" id="itemPlaceholder" style="display: inline-block" />
</LayoutTemplate>
<ItemTemplate>
<div class="SlideDiv">
<div>
<asp:ImageButton ID="ChangeDescriptionImageButton" runat="server" ImageUrl="~/Image/Change.png" CommandArgument="<%# Eval("ID") %>" CommandName="Change" AlternateText="Change" ToolTip="Change" />
<asp:Image ID="Image1" runat="server" CssClass="MiniSliderPic" ImageUrl='<%#Eval("ImagePath") %>' AlternateText='<%#Eval("Description") %>' ToolTip='<%#Eval("Description") %>' />
<p><%#Eval("Description").ToString().Replace(Environment.NewLine, "<br/>").Replace("\n", "<br />") %></p>
</div>
</div>
</span>
</ItemTemplate>
</asp:ListView>
and codebehind:
protected void SlidesListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
int ID = 0;
switch (e.CommandName)
{
case "Change":
ID = Convert.ToInt32(e.CommandArgument.ToString());
break;
}
}
but when I try to open this webform , I face this error:
An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
the server tag is not well formed
and asp:ImageButton tag get red.why?
Change this:
CommandArgument="<%# Eval("ID") %>"
To this:
CommandArgument='<%# Eval("ID") %>'
BTW, I don't think you can use imagebutton this way. It will fire it's won OnCommand rather than ListView's ItemCommand. Consider using a linkbutton with image inside it.
<asp:LinkButton ID="ChangeDescriptionLinkButton" runat="server"
CommandName="Change"
CommandArgument='<%# Eval("ID") %>' >
<img src="~/Image/Change.png" alt="Change" />Change
</asp:LinkButton>
Ive got a gridview with an itemtemplate that has a hyperlink control in it. I want to hide a hyperlink control if its item in the database returned null:
<ItemTemplate>
<asp:HyperLink ID="hlSugar" Visible=<% DataBinder.Eval(Container, "DataItem.CaseID")==null %> ToolTip="View the issue in SugarCRM." Target="_blank" runat="server" NavigateUrl='<%# "http://myPath&record=" + DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue"></asp:HyperLink>
</ItemTemplate>
Not sure on the syntax can I do
Visible = <% iif(databinder.eval(container, "dataItem.caseid")==null, false, true) %>
Not sure how to get the syntax correct. I basically want to check if my `DataItem.CaseID is null and hide this field if it is.
I ended up using this:
Visible='<%# Eval("SugarCaseID") != DBNull.Value %>'
visible='<%# Eval("dataItem.caseid") != null) %>'
Give this a shot
You can do this
bool ShowLink(obj data)
{
if(data!=null) {return true; } return false;
}
aspx:
<asp:HyperLink ID="hlSugar" Visible='<%# ShowLink(Eval("CaseID"))%>'
ToolTip="View the issue in SugarCRM." Target="_blank" runat="server"
NavigateUrl='<%# "http://myPath&record="
+ DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue">
</asp:HyperLink>
Use this
<asp:HyperLink ID="hlSugar" Visible='<%# Convert.ToBoolean(Eval("DataItem.CaseID").ToString() == "0") %>' ToolTip="View the issue in SugarCRM." Target="_blank" runat="server" NavigateUrl='<%# "http://myPath&record=" + DataBinder.Eval(Container, "DataItem.CaseID") %>' Text="Issue" />
REference:
Conditions within .aspx file for ListView ItemTemplate