riskyricky1972
asked on
asp.net 2.0 C# Griddata or Detailview and code behind.
asp.net 2.0 C# Griddata or Detailview and code behind.
I would like to setup Gridview or Detailview on the front end only for format because it is very easy, and use code-behind tech.
to make some "If" statement and make the flow control. How can I do that? I may need some good articles for this.
Or if you can show me working codes, you will get 500pts.
I would like to setup Gridview or Detailview on the front end only for format because it is very easy, and use code-behind tech.
to make some "If" statement and make the flow control. How can I do that? I may need some good articles for this.
Or if you can show me working codes, you will get 500pts.
Hi,
Sample
aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewList.asp x.vb" Inherits="Database_GridVie wList" %>
<!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" AutoGenerateColumns="False " AutoGenerateSelectButton=" True"
DataKeyNames="Id">
<Columns>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="Name" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" Height="50px"
Width="176px">
<Fields>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="Qul" />
</Fields>
</asp:DetailsView>
</div>
</form>
</body>
</html>
codebehind
Imports System.Data
Partial Class Database_GridViewList
Inherits System.Web.UI.Page
Dim ds As DataSet
Protected Sub GridView1_SelectedIndexCha nged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexCha nged
Dim dv As DataView = New DataView(ds.Tables("Child" ))
dv.RowFilter = "Id=" + Me.GridView1.SelectedValue .ToString( )
Me.DetailsView1.DataSource = dv
Me.DetailsView1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ds = Data()
If Not Me.IsPostBack Then
Me.GridView1.DataSource = ds.Tables("Parent")
Me.GridView1.DataBind()
End If
End Sub
Private Function Data() As DataSet
Dim dt As New DataTable
dt.Columns.Add("Id", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
dt.Rows.Add(New Object() {1, "aaaa"})
dt.Rows.Add(New Object() {2, "bbbb"})
dt.Rows.Add(New Object() {3, "cccc"})
dt.TableName = "Parent"
Dim dtc As New DataTable
dtc.Columns.Add("Id", GetType(Integer))
dtc.Columns.Add("Qul", GetType(String))
dtc.Rows.Add(New Object() {1, "aaaa"})
dtc.Rows.Add(New Object() {2, "bbbb"})
dtc.Rows.Add(New Object() {2, "bbbb"})
dtc.TableName = "Child"
Dim ds As New DataSet()
ds.Tables.Add(dt)
ds.Tables.Add(dtc)
Return ds
End Function
End Class
Sample
aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewList.asp
<!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" AutoGenerateColumns="False
DataKeyNames="Id">
<Columns>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="Name" />
</Columns>
</asp:GridView>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" Height="50px"
Width="176px">
<Fields>
<asp:BoundField DataField="Id" />
<asp:BoundField DataField="Qul" />
</Fields>
</asp:DetailsView>
</div>
</form>
</body>
</html>
codebehind
Imports System.Data
Partial Class Database_GridViewList
Inherits System.Web.UI.Page
Dim ds As DataSet
Protected Sub GridView1_SelectedIndexCha
Dim dv As DataView = New DataView(ds.Tables("Child"
dv.RowFilter = "Id=" + Me.GridView1.SelectedValue
Me.DetailsView1.DataSource
Me.DetailsView1.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ds = Data()
If Not Me.IsPostBack Then
Me.GridView1.DataSource = ds.Tables("Parent")
Me.GridView1.DataBind()
End If
End Sub
Private Function Data() As DataSet
Dim dt As New DataTable
dt.Columns.Add("Id", GetType(Integer))
dt.Columns.Add("Name", GetType(String))
dt.Rows.Add(New Object() {1, "aaaa"})
dt.Rows.Add(New Object() {2, "bbbb"})
dt.Rows.Add(New Object() {3, "cccc"})
dt.TableName = "Parent"
Dim dtc As New DataTable
dtc.Columns.Add("Id", GetType(Integer))
dtc.Columns.Add("Qul", GetType(String))
dtc.Rows.Add(New Object() {1, "aaaa"})
dtc.Rows.Add(New Object() {2, "bbbb"})
dtc.Rows.Add(New Object() {2, "bbbb"})
dtc.TableName = "Child"
Dim ds As New DataSet()
ds.Tables.Add(dt)
ds.Tables.Add(dtc)
Return ds
End Function
End Class
ASKER
Not useful
What is not useful, and why not?
ASKER
c# pls
My example above is C#, if you would like to use the example by madhevan_pillai, run it through a converter
http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
http://www.elegancetech.com/CSVB/CSVB.aspx?src=12
http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx
http://www.elegancetech.com/CSVB/CSVB.aspx?src=12
ASKER
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewList.asp x.vb" Inherits="Database_GridVie wList" %>
This is called c# code? Are you kidding me?
This is called c# code? Are you kidding me?
my mistake, but there is no need to be so rude,
You can help yourself, I am signing out of this post.
You can help yourself, I am signing out of this post.
Hey do u need C# code for the code behind?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="GridViewList.asp x.cs" Inherits="Database_GridVie wList" %>
i hope this would help you.
ASKER
But I will involve the stored procedure...
Hi,
you can invoke the stored procedure. The final outcome would be a dataset. so u can follow my sample code
you can invoke the stored procedure. The final outcome would be a dataset. so u can follow my sample code
ASKER
can you show me the completed code?
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
http://www.codeproject.com/useritems/GridViewDetailsView.asp