Link to home
Start Free TrialLog in
Avatar of riskyricky1972
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.

Avatar of RedKelvin
RedKelvin

Hi,

Sample

aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewList.aspx.vb" Inherits="Database_GridViewList" %>

<!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_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        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
Avatar of riskyricky1972

ASKER

Not useful
What is not useful, and why not?
c# pls
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewList.aspx.vb" Inherits="Database_GridViewList" %>

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.
Hey do u need C# code for the code behind?
ASKER CERTIFIED SOLUTION
Avatar of madhevan_pillai
madhevan_pillai
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="GridViewList.aspx.cs" Inherits="Database_GridViewList" %>

i hope this would help you.
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
can you show me the completed code?
Forced accept.

Computer101
EE Admin