C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Gridview row color change and opening a page against the click on the row


Posted Date: 14 May 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Olinur RahamanMember Level: Bronze    
Rating: Points: 10



// Design part

<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<br />
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
</asp:GridView>
<br />
<br />
</form>
</body>

//.aspx.cs page


public partial class _Default : System.Web.UI.Page
{
clsGrd gd = new clsGrd();

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
grd_bind();
}
}
public void grd_bind()
{
DataSet ds = new DataSet();
ds = gd.selectAll();
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';this.style.backgroundColor='orangered'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
e.Row.Attributes.Add("onclick", "window.open('Default2.aspx?id=" + DataBinder.Eval(e.Row.DataItem, "id") + "','myprofilewindow','width=400,height=200,toolbar=0,resizable=0');");

}
}
}


//class file


public class clsGrd
{
protected static string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection con = new SqlConnection(str);

public clsGrd()
{
//
// TODO: Add constructor logic here
//
}

public DataSet selectAll()
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlCommand cmd = new SqlCommand("selectall", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adp.Fill(ds);
return ds;
}


}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Example of using item command in datalist
Previous Resource: Check if the user is Administrator
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use