Visual Studio .NET - Show data in gridview vertically and update vertically also?

Asked By abhishek pundir on 25-Nov-08 01:15 AM

Hi,

I have displayed data in gridview vertically but i am not able to update it vertcally.

Please help me.

Thanx in advance!


Abhishek

re

Web Star replied to abhishek pundir on 25-Nov-08 01:31 AM

solution turned out to be  simple in the end

added a

OnRowDataBound="dlparent_rowdatabound"

event to gridview

 <gridview .....OnRowDataBound="dlparent_rowdatabound">

<columns> 

<asp:BoundField DataField="Classification" DataFormatString="<div class='Tableform' /><div class='TableformColleft' >Meeting:</div><div class='TableformColright' >{0}</div></div>" />

</columns>

</gridview>

Sub DLParent_Row(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

If e.Row.RowType = System.Web.UI.WebControls.DataControlRowType.DataRow Then

e.Row.Cells(0).Text = e.Row.Cells(0).Text & "<div class='Tableform' /><div class='TableformColleft' >Title:</div><div class='TableformColright' >" + e.Row.DataItem("Title").ToString + "</div></div>"

e.Row.Cells(0).Text = e.Row.Cells(0).Text & "<div class='Tableform' /><div class='TableformColleft' >Date:</div><div class='TableformColright' >" + e.Row.DataItem("DateOfMeeting").ToString.Format("{0:D}", e.Row.DataItem("DateOfMeeting")) + "</div></div>"

e.Row.Cells(0).Text = e.Row.Cells(0).Text & "<div class='Tableform' /><div class='TableformColleft' >Location:</div><div class='TableformColright' >" + e.Row.DataItem("Location").ToString + "</div></div>"

End If

End Sub

hope this helps someone

try this link

C_A P replied to abhishek pundir on 25-Nov-08 01:39 AM
http://www.codeproject.com/KB/webforms/MasterDetail.aspx

REply

Binny ch replied to abhishek pundir on 25-Nov-08 02:20 AM

I am not sure whether u can do it by using datagrid or not. But u can do it by using datalist.

Function CreateDataSource() As ICollection 

' Create sample data for the DataList control.
Dim dt As DataTable = New DataTable()
dim dr As DataRow

' Define the columns of the table.
dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))
dt.Columns.Add(New DataColumn("ImageValue", GetType(String)))

' Populate the table with sample values.
Dim i As Integer

For i = 0 To 8

dr = dt.NewRow()

dr(0) = i
dr(1) = "Description for item " & i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = "Image" & i.ToString() & ".jpg"

dt.Rows.Add(dr)

Next i

Dim dv As DataView = New DataView(dt)
Return dv

End Function

Sub Page_Load(sender As Object, e As EventArgs)

' Load sample data only once, when the page is first loaded.
If Not IsPostBack Then

ItemsList.DataSource = CreateDataSource()
ItemsList.DataBind()

End If

End Sub

Sub Button_Click(sender As Object, e As EventArgs)

' Set the repeat direction based on the selected value of the
' DirectionList DropDownList control.
ItemsList.RepeatDirection = _
CType(DirectionList.SelectedIndex, RepeatDirection)

' Set the repeat layout based on the selected value of the
' LayoutList DropDownList control.
ItemsList.RepeatLayout = CType(LayoutList.SelectedIndex, RepeatLayout)

' Set the number of columns to display based on the selected
' value of the ColumnsList DropDownList control.
ItemsList.RepeatColumns = ColumnsList.SelectedIndex

' Show or hide the gridlines based on the value of the
' ShowBorderCheckBox. Note that gridlines are displayed
' only if the RepeatLayout property is set to Table.
If ShowBorderCheckBox.Checked _
And ItemsList.RepeatLayout = RepeatLayout.Table Then

ItemsList.BorderWidth = Unit.Pixel(1)
ItemsList.GridLines = GridLines.Both

Else

ItemsList.BorderWidth = Unit.Pixel(0)
ItemsList.GridLines = GridLines.None

End If

End Sub

Check out the following link.

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.repeatdirection.aspx

Re :: Show data in Gridview Vertically and Update Vertically also
Shailendrasinh Parmar replied to abhishek pundir on 25-Nov-08 02:43 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FlipGridView.aspx.cs" Inherits="XmlPostData" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" ShowHeader="false" AllowSorting="true">
</asp:GridView>
</div>
</form>
</body>
</html>


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.Net;
using System.Text;
using System.IO;

public partial class FlipGridView:System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

GridView1.DataSource = FlipDataSet(c());
GridView1.DataBind();

}

public DataSet c()
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Company");
DataRow dr;
dt.Columns.Add(new DataColumn("accountNo", typeof(Int32)));
dt.Columns.Add(new DataColumn("CompanyName", typeof(string)));
dt.Columns.Add(new DataColumn("Address", typeof(string)));
for (int i = 0; i <= 10; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Company" + i + Environment.NewLine + "Title" + i;
dr[2] = "Address" + i + Environment.NewLine + "Title" + i;
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
return ds;
}
public DataSet FlipDataSet(DataSet my_DataSet)
{
DataSet ds = new DataSet();
foreach (DataTable dt in my_DataSet.Tables)
{
DataTable table = new DataTable();
for (int i = 0; i <= dt.Rows.Count; i++)
{
table.Columns.Add(Convert.ToString(i));
}
DataRow r = null;
for (int k = 0; k < dt.Columns.Count; k++)
{
r = table.NewRow();
r[0] = dt.Columns[k].ToString();
for (int j = 1; j <= dt.Rows.Count; j++)
r[j] = dt.Rows[j - 1][k];
table.Rows.Add(r);
}
ds.Tables.Add(table);
}

return ds;
}
}
Hope this helps.
Re :: Show data in Gridview Vertically and Update Vertically also
Shailendrasinh Parmar replied to abhishek pundir on 25-Nov-08 02:45 AM

See the following articles

http://www.codeproject.com/KB/aspnet/VerticalDatagrid.aspx

http://www.codeproject.com/KB/database/Vertical_rows_in_Datagrid.aspx

Hope this helps.