?
Solved

asp.net 2.0 C# Griddata or Detailview and code behind.

Posted on 2007-10-18
17
Medium Priority
?
185 Views
Last Modified: 2013-11-07
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.

0
Comment
Question by:riskyricky1972
  • 6
  • 5
  • 4
  • +1
16 Comments
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20105755
0
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 20106640
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
0
 

Author Comment

by:riskyricky1972
ID: 20106649
Not useful
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:RedKelvin
ID: 20106793
What is not useful, and why not?
0
 

Author Comment

by:riskyricky1972
ID: 20107191
c# pls
0
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20107975
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
0
 

Author Comment

by:riskyricky1972
ID: 20110346
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="GridViewList.aspx.vb" Inherits="Database_GridViewList" %>

This is called c# code? Are you kidding me?
0
 
LVL 22

Expert Comment

by:RedKelvin
ID: 20114346
my mistake, but there is no need to be so rude,

You can help yourself, I am signing out of this post.
0
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 20120936
Hey do u need C# code for the code behind?
0
 
LVL 12

Accepted Solution

by:
madhevan_pillai earned 2000 total points
ID: 20120957
aspx

<%@ Page Language="C#" 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

using System.Data;
partial class Database_GridViewList : System.Web.UI.Page
{
    DataSet ds;
    protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
    {
        DataView dv = new DataView(ds.Tables("Child"));
        dv.RowFilter = "Id=" + this.GridView1.SelectedValue.ToString();
        this.DetailsView1.DataSource = dv;
        this.DetailsView1.DataBind();
    }
   
    protected void Page_Load(object sender, System.EventArgs e)
    {
        ds = Data();
        if (!this.IsPostBack) {
            this.GridView1.DataSource = ds.Tables("Parent");
            this.GridView1.DataBind();
        }
    }
   
    private DataSet Data()
    {
       
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(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";
       
       
       
        DataTable dtc = new DataTable();
        dtc.Columns.Add("Id", typeof(int));
        dtc.Columns.Add("Qul", typeof(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";
       
       
        DataSet ds = new DataSet();
       
        ds.Tables.Add(dt);
        ds.Tables.Add(dtc);
       
        return ds;
       
    }
   
}

0
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 20120960
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="GridViewList.aspx.cs" Inherits="Database_GridViewList" %>

0
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 20120962
i hope this would help you.
0
 

Author Comment

by:riskyricky1972
ID: 20128841
But I will involve the stored procedure...
0
 
LVL 12

Expert Comment

by:madhevan_pillai
ID: 20129800
Hi,

you can invoke the stored procedure. The final outcome would be a dataset. so u can follow my sample code
0
 

Author Comment

by:riskyricky1972
ID: 20157316
can you show me the completed code?
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20324381
Forced accept.

Computer101
EE Admin
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question