Thursday, June 18, 2009

How to use repeater inside of the grid in c#




using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{


protected void Page_Load(object sender, EventArgs e)
{
binddata();
}

// Function to bind data in data controls..
public void binddata()
{
// your connection string here
string str = "Data Source=.;Initial Catalog=master;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
DataSet ds = new DataSet();
// name of your stored procedure,
SqlDataAdapter da = new SqlDataAdapter("getCompNews", con);
da.Fill(ds);

ds.Relations.Add("InnerVal",
ds.Tables[0].Columns["compname"],
// making a relation between two tables.
ds.Tables[1].Columns["compname"]);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnkMore = (LinkButton)e.Row.FindControl("link");
Label lbl = (Label)e.Row.FindControl("Label1");
lnkMore.PostBackUrl = "~/Company.aspx?cmp=" + lbl.Text;
}
}
}

No comments:

Post a Comment