asp:imagebutton hover effect css - asp.net

I have the buttons below working so that the buttond do what they have to, but i would like to add a CSS so that they can hover is there any method of doing this.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataKeyNames="pageID"
DataSourceID="SQLData" AutoGenerateColumns="False"
PageSize="1" Width="100%" Height="500px"
GridLines="None" ShowHeader="False" >
<Columns>
<asp:BoundField DataField="pageID" HeaderText="pageID" InsertVisible="False"
ReadOnly="True" SortExpression="pageID" ShowHeader="False" Visible="False" />
<asp:BoundField DataField="sectionID" HeaderText="sectionID"
SortExpression="sectionID" Visible="False" ShowHeader="False" />
<asp:BoundField DataField="pageNo" HeaderText="pageNo" SortExpression="pageNo"
Visible="False" ShowHeader="False" />
<asp:BoundField DataField="pageTitle" HeaderText="pageTitle"
SortExpression="pageTitle" Visible="False" ShowHeader="False" />
<asp:TemplateField HeaderText="pageContent" SortExpression="pageContent"
ShowHeader="False" ItemStyle-CssClass="pagecontent">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("pageContent") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblPageContent" runat="server" Text='<%# Bind("pageContent") %>' CssClass="pageContent"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Mode="NextPrevious"
NextPageImageUrl="~/images/navButtonNext.png" NextPageText="Next Page"
PreviousPageImageUrl="~/images/navButtonPrevious.png" PreviousPageText="Previous Page" LastPageImageUrl="images/navButtonNext.png" />
<PagerStyle CssClass="navPager" HorizontalAlign="Right" />
<PagerTemplate>
<asp:ImageButton ID="navBack" runat="server"
ImageUrl="~/images/navigation/grey_bttn_back.jpg" CssClass="sec" CommandName="Page" CommandArgument="Prev" ClientIDMode="Static" AlternateText="Back" ToolTip="Back" />
<asp:ImageButton ID="navHome" runat="server"
ImageUrl="~/images/navigation/grey_bttn_up.jpg" CommandName="gotoHome" ClientIDMode="Static" AlternateText="Home" ToolTip="Home" />
<asp:ImageButton ID="navFwd" runat="server"
ImageUrl="~/images/navigation/grey_bttn_fwd.jpg" CommandName="Page" CommandArgument="Next" ClientIDMode="Static" AlternateText="Fwd" ToolTip="Fwd" />
</PagerTemplate>
</asp:GridView>

You need JavaScript to do this. Bind your image buttons in mouse move event and add a class something like "hover" to the image button if mouse is hovered on it. Use your Css to style if the image button contains class.
<script type="text/javascript">
window.onload=function(){
document.getElementById("navBack").onmousemove=function(){
this.setAttribute('class', 'hover');
document.getElementById("navHome").className="";
document.getElementById("navFwd").className="";
}
document.getElementById("navHome").onmousemove=function(){
this.setAttribute('class', 'hover');
document.getElementById("navBack").className="";
document.getElementById("navFwd").className="";
}
document.getElementById("navFwd").onmousemove=function(){
this.setAttribute('class', 'hover');
document.getElementById("navHome").className="";
document.getElementById("navBack").className="";
}
}
</script>
Note: Don't forget to remove class name from image buttons if mouse is not hovered on them. Use css effects you want for the class "hover".

Related

Move the GridView Add button to right of delete button?

The attached screenshot shows two images.
Is it possible to make to Add button and delete button align side by side as depicted by the bottom image?
We are currently using GridView to create dynamic rows and it gets bit too long helped in part by the position of the Add button
<asp:gridview ID="grvCustomers" GridLines="None" runat="server" ShowFooter="true" AutoGenerateColumns="false" OnRowDeleting="grvCustomers_RowDeleting">
<Columns>
<asp:BoundField DataField="RowNumber" Visible="false" HeaderText="Row Number" />
<asp:TemplateField HeaderText="Customer Name">
<ItemTemplate>
<asp:TextBox ID="custname" runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Adress">
<ItemTemplate>
<asp:TextBox ID="custaddress" runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="custamount" runat="server" style="width:250px;" class="form-control"></asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Right" />
<FooterTemplate>
<asp:Button ID="ButtonAdd" runat="server" Text="Add More"
onclick="ButtonAdd_Click" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:gridview>
I second what #ahwm said.
But also, if the goal is to add the record to the data source, couldn't you simply add the commandfield showinsertbutton="true".

Asp GridView make hyperlink column editable

I have asp:GridView. I can edit all columns without problems, except this one:
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="hyperlinkEdocs" runat="server" Target="HyperLink"
HeaderText="Dopolnitve (eDocs)"
NavigateUrl='<%# String.Format("http://{0}", Eval("CUSTOMER").ToString()) %>'
Text='<%# Eval("CUSTOMER") %>'></asp:HyperLink>
</ItemTemplate>
I am editing columns by click on 'Edit' link (this triggers that columns content is displayed in a text boxes).
How can I make this column editable, so I will be able to edit and update hyperlink in column?
<asp:GridView runat="server" ID="gvrecords" AutoGenerateColumns="false"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" />
</Columns>
</asp:GridView
I'm not 100% sure what you are trying to do because I can't see your code behind but why don't you use an edit item template?
<asp:TemplateField HeaderStyle-Width="100px" HeaderText = "ABC">
<ItemTemplate>
<asp:Label ID="label" runat="server"
Text='<%# Eval("id")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="textbox1" Width="100px" Height="50px" runat="server"
Text='<%# Eval("id")%>'></asp:TextBox>
</EditItemTemplate>
<HeaderStyle Width="80px" HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
Edit link click open textbox
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
grd_view();
}

focus a div on link button click

In my page, I have a gridview with link buttons in a column.
By clicking the link button should show a div below the gridview.
I gave href in onClientClick event of the link button as follows.
function showDiv() {
location.href = '#div1';
}
When I click the link button the div is showing, but after the page load the page goes up.
aspx code
<asp:GridView ID="gridDate" runat="server" CssClass="gridview_Order"
HeaderStyle-BackColor="#09182F" HeaderStyle-ForeColor="#ffffff"
AutoGenerateColumns="false" Visible="False">
<Columns>
<asp:TemplateField ItemStyle-Width="20%" HeaderText="Sl No." ItemStyle-CssClass="paddng">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="DATE" ItemStyle-CssClass="paddng">
<ItemTemplate>
<asp:LinkButton ID="lbtnDate" runat="server" CommandArgument='<%#Eval("tblName") %>' Text='<%# Eval("dtvar") %>' OnClientClick="showDiv()" OnCommand="lbtnDate_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="25%" HeaderText="" ItemStyle-CssClass="paddng">
<ItemTemplate>
<asp:LinkButton ID="lbtnDownload" runat="server" Text="Download Excel" CommandArgument='<%# Eval("tblName") %>' OnCommand="lbtnDownload_Click"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br /><hr /><br />
<div id="div1">
<asp:GridView ID="gridOrderByUser" runat="server" CssClass="gridview"
HeaderStyle-BackColor="#09182F" HeaderStyle-ForeColor="#ffffff"
AutoGenerateColumns="false" Visible="False" >
<Columns>
<asp:TemplateField ItemStyle-Width="2%" HeaderText="Sl No.">
<ItemTemplate>
<asp:Label ID="lblSlNo1" runat="server" Text='<%#Container.DataItemIndex+1 %>' style="color:#000;"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cod" HeaderText="CODE" InsertVisible="False" ReadOnly="True" SortExpression="cod" ItemStyle-Width="16%" />
<asp:TemplateField HeaderText="IMAGE" ItemStyle-Width="18%">
<ItemTemplate>
<asp:Image ID="img1" runat="server" Height="100px" Width="54px" ImageUrl='<%#"~/images/"+Eval("Image") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
So what should I do for staying the page in the div position.
Thanks
If you dont need the server side event of the link button you could do this:
OnClientClick="location.href = '#div1'; return false;"

ASPX GridView header name?

How do we access the header above the edit and delete buttons? I would like to put some text there instead of it being empty.
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:LinkButton ID="btnInsert" runat="server"
Text="Insert" CommandName="Insert" ForeColor="White" />
</HeaderTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
<asp:CommandField HeaderText="Delete" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
you can add text to header column to gridview column of edit button.
<asp:GridView ID="grdviewlst" runat="server" >
<Columns>
<asp:TemplateField HeaderText="Actions">
<ItemTemplate>
<asp:Button ID="btnedit" CssClass="btnclassedit" runat="server" CommandName="EDIT"
Text="Edit" ToolTip="Edit" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Width of the columns in GridView is not fixed

I try different "properties":
ItemStyle-Width
ControlStyle-Width
HeaderStyle-Width
I set ItemStyle-Wrap in "true".
I use css class:
.wraptext
{
word-wrap:break-word;
-ms-word-wrap: break-word;
-moz-word-wrap: break-word;
-webkit-word-wrap: break-word;
}
It didn't help me. My GridView:
<asp:Panel ID="Panel2" Height="570px" Width="100%" runat="server" ScrollBars="Vertical" BackColor="White">
<asp:GridView ID="tableResults" runat="server" DataSourceID="sourceDetails"
AutoGenerateColumns="False" OnDataBound="tableResults_Bound"
OnRowDataBound = "tableResults_DataBound" DataKeyNames="i_id"
AutoGenerateDeleteButton="True" OnRowDeleted="tableResults_RowDeleted"
AutoGenerateEditButton = "True" OnRowUpdating="tableResults_RowUpdating"
OnRowUpdated="tableResults_RowUpdated" AllowSorting="true" AllowPaging="true" PageSize="150"
Height="300px" BorderStyle="None" Font-Size="12px">
<RowStyle BorderColor="Black" />
<Columns>
<asp:TemplateField HeaderText="Код патча" SortExpression="patchcode" ItemStyle-Width="4%">
<HeaderStyle Width="4%" />
<ItemTemplate>
<asp:Label Width="4%" ID="lblPatchCode" runat="server" Text='<%# Eval("patchcode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderStyle-Width="3%" ItemStyle-Width="3%" DataField="i_number" ReadOnly="true" HeaderText="П/п" SortExpression="i_number"/>
<asp:BoundField HeaderStyle-Width="20%" ItemStyle-CssClass="wraptext" ItemStyle-Width="20%" DataField="s_name" ReadOnly="true" HeaderText="Наименование работы" SortExpression="s_name"/>
<asp:TemplateField HeaderText="Статус" SortExpression="status" ItemStyle-Width="7%">
<HeaderStyle Width="7%" />
<ItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("status")%>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("status")%>' Visible = "false"></asp:Label>
<asp:DropDownList AutoPostBack="true" OnSelectedIndexChanged="ddl_OnSelectedIndexChanged"
ID="ddlStatuses" runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
CSS3 word-wrap Property is an CSS3 feature so that would work in modern browsers only which support the css3 word-wrap
For fallback to non-supportive browsers use .NET GridView in conjuction with Eval and public method in page-behind to break the letters.

Resources