How do I specify more than one parameter for my HyperlinkColumn?

<asp:DataGrid id=’DataGrid1′ runat=’server’ AutoGenerateColumns=’False’> <Columns> <asp:TemplateColumn HeaderText=’Sample Column’> <ItemTemplate> <asp:Hyperlink runat=’server’ Text=’<%#DataBinder.Eval(Container.DataItem, ‘ProductName’).ToString()%>’ NavigateUrl=’<%# ‘page1.aspx?id=’ + DataBinder.Eval(Container.DataItem,’ProductId’).ToString() + ‘&Name=’ + DataBinder.Eval(Container.DataItem,’ProductName’).ToString()%>’ ID=’Hyperlink1′ NAME=’Hyperlink1’/> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid>

How to populate a DataGrid using a DataSet

<asp:DataGrid id=’DataGrid1′ runat=’server’></asp:DataGrid> Use the namespace System.Data.SqlClient VB.NET Dim cn As SqlConnection Dim da As SqlDataAdapter Dim ds As DataSet Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load cn = New SqlConnection(‘Server=localhost;uid=sa;pwd=;database=northwind’) da = New SqlDataAdapter(‘Select * from products’, cn) ds = New DataSet da.Fill(ds, ‘Products’) DataGrid1.DataSource = ds.Tables(0) ’DataGrid1.DataSource = ds ’DataGrid1.DataSource = ds.Tables(‘Product’) DataGrid1.DataBind() End Sub C# SqlConnection cn; SqlDataAdapter da; DataSet ds; private void Page_Load(object sender, System.EventArgs e) { cn= new SqlConnection (‘Server=localhost;uid=sa;pwd=;database=northwind’); da= new SqlDataAdapter (‘SELECT * FROM Products ‘, cn); ds= new DataSet (); da.Fill (ds, ‘Product’); DataGrid1.DataSource =ds.Tables[0]; //DataGrid1.DataSource= ds; //DataGrid1.DataSource= ds.Tables[‘Products’]; DataGrid1.DataBind (); }

How to populate a DataGrid using a DataReader

<asp:DataGrid id=’DataGrid1′ runat=’server’></asp:DataGrid> Use Namespace System.Data.SqlClient VB.NET Dim cn As SqlConnection Dim cmd As SqlCommand Dim rdr As SqlDataReader Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ’Put user code to initialize the page here Try cn = New SqlConnection(‘server=localhost;uid=sa;pwd=;database=northwind’) cmd = New SqlCommand(‘select * from employees ‘, cn) cn.Open() rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection) DataGrid1.DataSource = rdr DataGrid1.DataBind() Catch ex As Exception Response.Write(ex.Message.ToString()) Finally rdr.Close() cn.Close() End Try End Sub ’Page_Load C# SqlConnection cn ; SqlCommand cmd ; SqlDataReader rdr ; private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here try { cn = new SqlConnection(‘server=localhost;uid=sa;pwd=;database=northwind’); cmd = new SqlCommand( ‘select * from employees ‘, cn); cn.Open(); rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection ); DataGrid1.DataSource = rdr; DataGrid1.DataBind(); } catch (Exception ex) { Response.Write (ex.Message.ToString ()); } finally { rdr.Close(); cn.Close(); } }

How to use a Table control to display data vertically

<asp:Table id=’Table1′ runat=’server’></asp:Table> VB.NET ’Populate the DataSet ds Dim dr As DataRow For Each dc In ds.Tables(0).Columns Dim trow As New TableRow() Dim tcellcolname As New TableCell() ’To Display the Column Names For Each dr In ds.Tables(0).Rows tcellcolname.Text = dc.ColumnName trow.BackColor = System.Drawing.Color.Beige tcellcolname.BackColor = System.Drawing.Color.AliceBlue ’Populate the TableCell with the Column Name tcellcolname.Controls.Add(New LiteralControl(dc.ColumnName.ToString)) Next trow.Cells.Add(tcellcolname) ’To Display the Column Data For Each dr In ds.Tables(0).Rows Dim tcellcoldata As New TableCell() ’Populate the TableCell with the Column Data tcellcoldata.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString)) trow.Cells.Add(tcellcoldata) Next Table1.Rows.Add(trow) Next C# //Populate the DataSet ds foreach(DataColumn dc in ds.Tables[0].Columns ) { TableRow trow = new TableRow(); TableCell tcellcolname = new TableCell() ; foreach(DataRow dr in ds.Tables[0].Rows ) { tcellcolname.Text = dc.ColumnName ; trow.BackColor = System.Drawing.Color.Beige ; tcellcolname.BackColor = System.Drawing.Color.AliceBlue ; //Populate the TableCell with the Column Name tcellcolname.Controls.Add(new LiteralControl(dc.ColumnName.ToString())) ; } trow.Cells.Add(tcellcolname) ; //To Display the Column Data foreach(DataRow dr in ds.Tables[0].Rows ) { TableCell tcellcoldata =new TableCell() ; //Populate the TableCell with the Column Data tcellcoldata.Controls.Add(new LiteralControl(dr[dc.ColumnName].ToString())) ; trow.Cells.Add(tcellcoldata); } Table1.Rows.Add(trow) ; }

How to create a table control dynamically to populate data

<asp:Table id=’Table1′ runat=’server’></asp:Table> VB.NET Dim mycn As SqlConnection Dim myda As SqlDataAdapter Dim ds As DataSet mycn = New SqlConnection(‘server = localhost;uid=sa;password=;database=northwind’) myda = New SqlDataAdapter(‘Select Employeeid, FirstName , LastName from employees’, mycn) ds = New DataSet myda.Fill(ds, ‘Employees’) Dim dc As DataColumn Dim dr As DataRow For Each dr In ds.Tables(0).Rows Dim trow As New TableRow For Each dc In ds.Tables(0).Columns Dim tcell As New TableCell tcell.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString)) trow.Cells.Add(tcell) Next Table1.Rows.Add(trow) Next C# SqlConnection mycn ; SqlDataAdapter myda ; DataSet ds ; mycn = new SqlConnection(‘server = localhost;uid=sa;password=;database=northwind’); myda = new SqlDataAdapter(‘Select Employeeid, FirstName , LastName from employees’, mycn); ds = new DataSet(); myda.Fill(ds, ‘Employees’); TableRow trow ; TableCell tcell; foreach (DataRow dr in ds.Tables[0].Rows) { trow = new TableRow (); foreach( DataColumn dc in ds.Tables[0].Columns) { tcell= new TableCell (); tcell.Controls.Add(new LiteralControl(dr[dc.ColumnName].ToString())); trow.Cells.Add(tcell); } Table1.Rows.Add(trow); }