Archive

Archive for April, 2013

GridView Row Color Change On Mouse Hover

April 22, 2013 Leave a comment

Hi all,

try this example to change Gridview Row Color on MouseHover

1) Open VS 2008 and create a new web site and add new web Page

2) From ToolBox Drag and Drop Gridview control in your ASPX Page

<asp:GridView ID="GridView1" runat="server" OnRowCreated="GridView1_RowCreated"></asp:GridView>

In code behind :


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class _Default : System.Web.UI.Page
{
 SqlConnection con = new SqlConnection("Data Source=Northwind;Integrated Security=true;Initial Catalog=session");
 protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack)
 {
 BindGridview();
 }
 }
 protected void BindGridview()
 {
 con.Open();
 SqlCommand cmd = new SqlCommand("select * from Customers", con);
 SqlDataAdapter da = new SqlDataAdapter(cmd);
 DataSet ds = new DataSet();
 da.Fill(ds);
 con.Close();
 GridView1.DataSource = ds;
 GridView1.DataBind();

}
 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
 {
 e.Row.Attributes.Add("onMouseOver", "this.style.background='#cccccc'");
 e.Row.Attributes.Add("onMouseOut", "this.style.background='#ffffff'");
 }
}

Hope this helps

Good Luck.

Advertisements
Categories: ASP.Net

Show and Hide row in ListView according to Condition

April 20, 2013 Leave a comment

Dear all,

try this example to Show and Hide row in ListView according to Condition


<asp:ListView ID="MusicList" runat="server">
 <ItemTemplate>
 <tr runat="server" Visible='<%# Eval("DownloadLink") != null ? true : false %>'>
 <td>
 <a href="<%#Eval("DownloadLink") %>">Link</a>
 </td>
 </tr>
 </ItemTemplate>
</asp:ListView>

Hope this helps

Good Luck.

Categories: ASP.Net

Disable and Enable Validation Controls in a GridView by CheckBox Click

April 9, 2013 Leave a comment

Hi all,

try this example to Disable and Enable Validation Controls in a GridView by CheckBox Click

1) Open VS2008 and create new web site and add new web page

2) From ToolBox add Gridview control and Bind it to Categories table in Northwind database using SQLDataSource control


<div>
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
 CellPadding="4" DataKeyNames="CategoryID" DataSourceID="SqlDataSource1"
 ForeColor="#333333" GridLines="None" onrowdatabound="GridView1_RowDataBound">
 <RowStyle BackColor="#EFF3FB" />
 <Columns>
 <asp:TemplateField>
 <ItemTemplate>
 <asp:CheckBox ID="cbx_ID" runat="server" ToolTip='<%# Eval("CategoryID") %>' />
 </ItemTemplate>
 </asp:TemplateField>
 <asp:BoundField DataField="CategoryID" HeaderText="CategoryID"
 InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />
 <asp:BoundField DataField="CategoryName" HeaderText="CategoryName"
 SortExpression="CategoryName" />
 <asp:TemplateField HeaderText="Quantity">
 <ItemTemplate>
 <asp:TextBox ID="txt_Quantity" runat="server"></asp:TextBox>
 <asp:RequiredFieldValidator ID="rfv_Quantity" runat="server"
 ControlToValidate="txt_Quantity" Enabled="False"
 ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
 </ItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Price">
 <ItemTemplate>
 <asp:TextBox ID="txt_Price" runat="server"></asp:TextBox>
 <asp:RequiredFieldValidator ID="rfv_Price" runat="server"
 ControlToValidate="txt_Price" Enabled="False"
 ErrorMessage="RequiredFieldValidator">*</asp:RequiredFieldValidator>
 </ItemTemplate>
 </asp:TemplateField>
 </Columns>
 <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
 <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
 <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
 <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
 <EditRowStyle BackColor="#2461BF" />
 <AlternatingRowStyle BackColor="White" />
 </asp:GridView>
 <asp:SqlDataSource ID="SqlDataSource1" runat="server"
 ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
 SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]">
 </asp:SqlDataSource>
 </div>
 <asp:Button ID="btn_Save" runat="server" Text="Save Data" />

3) Add the following Jaavscript code to Enable and Disable Validation Control according to Checkbox


<script type="text/javascript">
 function EnableDisableValidation(cbx, qty, price) {
 var cbx_ID = document.getElementById(cbx);
 var rfv_qty = document.getElementById(qty);
 var rfv_price = document.getElementById(price);

 if (cbx_ID.checked) {
 ValidatorEnable(rfv_qty, true);
 ValidatorEnable(rfv_price, true);
 }
 else {
 ValidatorEnable(rfv_qty, false);
 ValidatorEnable(rfv_price, false);
 }
 }
 </script>

4) In Code behind add the following code


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
 if (e.Row.RowType == DataControlRowType.DataRow)
 {
 CheckBox cbx_ID = (CheckBox)e.Row.FindControl("cbx_ID");
 RequiredFieldValidator rfv_Quantity = (RequiredFieldValidator)e.Row.FindControl("rfv_Quantity");
 RequiredFieldValidator rfv_Price = (RequiredFieldValidator)e.Row.FindControl("rfv_Price");

cbx_ID.Attributes.Add("onclick", "javascript:EnableDisableValidation('" + cbx_ID.ClientID + "','" + rfv_Quantity.ClientID + "','" + rfv_Price.ClientID + "')");

}
 }

Hope this helps

Good Luck.

Categories: ASP.Net, Javascript

Use Calculated Field in SharePoint 2010

April 5, 2013 2 comments

Hi all,

try this example to use Calculated Field in SharePoint 2010

Step 1: Open SharePoint 2010 Central Administration and navigate to a specific site

Step 2: Create a new custom list call it “Company”

create-custom-list-in-sharepoint

Step 3:  Add new columns and design view of the created new list looks like this

design-of-custom-list-in-sharepoint

Step 4: Creating a calculated field with formula output of the application looks like this:

formula-output-in-sharepoint

Step 5: The output of employee data form looks like this:

output-of-custom-list-in-sharepoint1

Step 6: The output of list data entering form looks like this:

output-of-custom-list-in-sharepoint2

Step 7: The output of list data entered looks like this:

custom-listdata-in-sharepoint

 

Hope this helps

Good Luck.

Categories: SharePoint 2010

Remove First and Last Character from string using SQL

April 4, 2013 Leave a comment

Hi all,

try this example to Remove First and Last Character from string using SQL Server

— To remove first character from string try this example :


Declare @name as varchar(30)
set @name='Yasser'
Select right(@name, len(@name)-1) as AfterRemoveFistCharacter

— To remove the last character from a string try this example :


Declare @name as varchar(30)
set @name='Yasser'
Select left(@name, len(@name)-1) as AfterRemoveLastCharacter

— To remove both (the first and last) character from a string try this example :


Declare @name as varchar(30)
set @name='Yasser'
Declare @n varchar(40)
set @n=left(@name, len(@name)-1)
Select right(@n, len(@n)-1)

Hope this helps

Good Luck.

 

Categories: SQL Server