Disable a hyperlink
-
I have a datagrid with various BoundColumns and HyperLinkColumns. All of the columns work great. The problem is that I am creating a list for data entry. If the data has already been entered I want to disable the Entry Hyperlink and Enable the View/Edit Hyperlink, and visa versa if the entry has not been made I want the Entry HyperLink to be Enabled and the View/Edit HyperLink to be Disabled. If there was a way to create an ID for the column I could handle it in the ItemDataBound Event in the behind code, but I have not found a way to create an ID field for the HyperLinkColumn. Could someone assist with a code sample for ASP.NET...
-
I have a datagrid with various BoundColumns and HyperLinkColumns. All of the columns work great. The problem is that I am creating a list for data entry. If the data has already been entered I want to disable the Entry Hyperlink and Enable the View/Edit Hyperlink, and visa versa if the entry has not been made I want the Entry HyperLink to be Enabled and the View/Edit HyperLink to be Disabled. If there was a way to create an ID for the column I could handle it in the ItemDataBound Event in the behind code, but I have not found a way to create an ID field for the HyperLinkColumn. Could someone assist with a code sample for ASP.NET...
It could be done easily using this :
.disabledLink
{
color: #333;
text-decoration : none;
cursor: default;
}Use this Javascript to do this in client side.
function disablelink(linkID)
{
var hlink = document.getElementById(linkID);
if(!hlink)
return;hlink.href = "#";
hlink.className = "disableLink";
}or in ItemDataBound use :
ctrl.CssClass = "disabledLink";
ctrl.Href = "#";It will be disabled. :cool: Why do you require to create ID. If you place the server side ID, you might use ClientId to get what id is generated in the client. ;)
Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
I have a datagrid with various BoundColumns and HyperLinkColumns. All of the columns work great. The problem is that I am creating a list for data entry. If the data has already been entered I want to disable the Entry Hyperlink and Enable the View/Edit Hyperlink, and visa versa if the entry has not been made I want the Entry HyperLink to be Enabled and the View/Edit HyperLink to be Disabled. If there was a way to create an ID for the column I could handle it in the ItemDataBound Event in the behind code, but I have not found a way to create an ID field for the HyperLinkColumn. Could someone assist with a code sample for ASP.NET...
protected void gvPaymentDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = e.Row;if (gvr.Cells\[5\].Text != " " || gvr.Cells\[6\].Text != " " || gvr.Cells\[8\].Text != "0") { ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = false; ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled = True; } else { ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = True; ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled =False; } } }
I am using this code in my appliction for edit and add button.
-
protected void gvPaymentDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridViewRow gvr = e.Row;if (gvr.Cells\[5\].Text != " " || gvr.Cells\[6\].Text != " " || gvr.Cells\[8\].Text != "0") { ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = false; ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled = True; } else { ((LinkButton)(e.Row.FindControl("lbEdit"))).Enabled = True; ((LinkButton)(e.Row.FindControl("lbEntry"))).Enabled =False; } } }
I am using this code in my appliction for edit and add button.
-
Will ASP.NEt treat the LinkButton the same as the HyperlinkColumn with all of the same properties like DataNavigateUrlField and DataNavigateUrlFormatString?
i think it will work in hyperlink columns 2 but why dont u use this code
<Columns>
asp:TemplateColumn
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>use itemtemplate for hyperlinks
-
i think it will work in hyperlink columns 2 but why dont u use this code
<Columns>
asp:TemplateColumn
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>use itemtemplate for hyperlinks
-
i think it will work in hyperlink columns 2 but why dont u use this code
<Columns>
asp:TemplateColumn
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>use itemtemplate for hyperlinks
-
i think it will work in hyperlink columns 2 but why dont u use this code
<Columns>
asp:TemplateColumn
<ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server">Edit</asp:LinkButton>
<asp:LinkButton ID="lnkView" runat="server">View</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>use itemtemplate for hyperlinks
I like the looks of this implementation except that it feel like a total rewrite of the ASP page because the page binds data to both BoundColumns and HyperLinkColumns. To date I have not attempted to bind data to a LinkButton. Is this possible? or would I Have to move all of the naturally bound data to the ItemDataBound method and then launch the enbedded JavaScript from the ItemCommand method?
-
asp:TemplateField
<ItemTemplate><asp:LinkButton ID="lbEdit" runat="server" Text="Edit" OnClick="lbEdit\_Click"></asp:LinkButton> </ItemTemplate> </asp:TemplateField>
i am redirecting from aspx only.
LinkButton btn = sender as LinkButton;
GridViewRow gvr = btn.NamingContainer as GridViewRow;
string docNo = gvr.Cells[0].Text;so this way i am fetching row datakey
-
I like the looks of this implementation except that it feel like a total rewrite of the ASP page because the page binds data to both BoundColumns and HyperLinkColumns. To date I have not attempted to bind data to a LinkButton. Is this possible? or would I Have to move all of the naturally bound data to the ItemDataBound method and then launch the enbedded JavaScript from the ItemCommand method?