Highlighting GridView Row on MouseOver

Of late , i've  been receiving  E-Mails  asking for  publishing  the content  for BEGINNERS  in  .NET ,  So  i've decided  to  include  some  new posts  for  them .

 

In  this  article  , we'll  see  how  we  can  change  the  row color  of  a  GridView  when   anyone   moves  their mouse over  the GridView .  So  let's get it  started.

1) Create  a  page name Test.aspx

 

Test.aspx ( HTML Markup)

 <div class="TEST">
    <asp:GridView  ID="GV1" runat="server" >
        <Columns>
                  <asp:TemplateField>
                          <ItemTemplate>
  
                                 <asp:LinkButton ID="Link1"  runat="server" Text='<%# Eval("FirstName") %>' CommandName="LINK"   ></asp:LinkButton>
                         </ItemTemplate>
                  </asp:TemplateField>
       </Columns>
    </asp:GridView>
       
  </div>

 

Test.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            con = new SqlConnection("uid=sa;pwd=123456;database=Talib");
            con.Open();
            da = new SqlDataAdapter("select  * from tblRegistration order by id desc", con);
            ds = new DataSet();
            da.Fill(ds);
            GV1.DataSource = ds;  // GV1 is  the name of  GridView
            GV1.DataBind();
        }

        catch (Exception ex)
        {
            Response.Write(ex.Message);

        }
        finally
        {
            con.Close();
        }

    }

 

2)  Now  we  need to  assign  the  CSS  styling  for this   GridView  ,  illustrated  below

<style type="text/css">
        .TEST div table tr:hover
    {
          background-color:silver;
    }

</style>

 

Now, we're done.  Execute  the  page  and  see how  it  works.

 

 

I  hope you people like this post ,till  then  enjoy  Programming ......   Smile

 


Tags: , , , , ,
Categories: ASP.NET

17 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

ASP.NET AJAX Auto Complete Extender with Database

Of late, there has been a lot of speculation about AJAX Control Toolkit's AutoComplete Extender. Basically , this control loads the data specific to the entered text..
So now we will see as to how to connect this control to database and fetch the data when the user enters a specific word or phrase.....

AutoComplete.aspx


 

 

Now let us see the code for web service that will help us in fetching the data..

AutoComplete.cs

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class AutoComplete : WebService
{
[WebMethod]

public string[] SearchDB(string prefixText, int count)
{
if (count == 0)
{
count = 10;
}

SqlConnection con = new SqlConnection("server=localhost;database=your database;uid=your username;pwd=your pwd");

string str = "select * from table where username like @prefixText";
con.Open();
SqlDataAdapter da = new SqlDataAdapter(str, con);

da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText + "%";
DataSet ds = new DataSet();
da.Fill(ds);

int cnt = ds.Tables[0].Rows.Count;
List items = new List(cnt);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{


items.Add(ds.Tables[0].Rows[i]["UserName"].ToString());
}
return items.ToArray();

}
}


Stylesheet.css
/* AutoComplete highlighted item */

.autocomplete_highlightedListItem
{
background-color: #ffff99;
color: black;
padding: 1px;
}

/* AutoComplete item */

.autocomplete_listItem
{
background-color : window;
color : windowtext;
padding : 1px;
}

Now let's check out the result after running the application ..

 

 

 


NOTE:Please do comment regarding the article as it'll help me to write even more specifically..


Tags: , , , , , ,
Categories: ASP.NET

40 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

App_Offline.htm .... Taking an ASP.NET 2.0 application offline

Sometimes what happens is , when you are working on some maintainence stuff on your website , then you need to STOP the application from functioning. This could prove to be a tedious task . So as a solution to this ,comes another amazing feature of Visual Studio.Net which we will see in the coming lines below.

Create a file named "app_offline.htm" in the root of the application . When ASP.NET sees it, it will shut-down the app-domain for the application (and not restart it for requests) and instead send back the contents of the app_offline.htm file in response to all new dynamic requests for the application. So when you are done updating the site, just delete the file and it will come back online.

So if you use the app_offline.htm feature, you should make sure you have at least 512 bytes of content within it to make sure that your HTML shows up to your users.

For example :

This page is U N D E R C O N S T R U C T I O N !!. Please visit after sometime. Thank You !!


Tags: , , , ,
Categories: ASP.NET

4 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

Detecting User's IP Address

If your website contains sensitive data and you don't want any spamming or any malicious use of your website ,then one thing you can do is to keep a track of the visiting user's system IP and this can be done in some easy steps given below,


string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();


Now set the value of clientIPAddress to either a Textbox or label or any control as per your requirement.


Tags: , , , , , ,
Categories: ASP.NET

23 Comments
Actions: E-mail | Permalink | Comment RSSRSS comment feed

 


© Copyright 2009. www.onlineasp.net All Rights Reserved.