Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 28th, 2008, 04:51 AM
Authorized User
 
Join Date: Jun 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Add

Hi,

I have designed an aspx page in which i am having a gridview.
I used SQL server as backend and my database database name is "sample"
I created a stored procedure to select employee name from "emp" table from "sample" database and filled it to a dataset.
I had filled that gridview with that dataset and loaded employee names and Id.
I want to append a Datatable that contains only one static row into the same dataset.

If data inside "emp" table is

empId empName

1 Subha
2 Harshini



Then, during page load, along with these 2 rows, a third row as,


3 New

should be added to dataset.The output should be as below.

empId empName

1 Subha
2 Harshini
3 New


The source code I used is shown below.

In Grid.aspx.cs, the following code is used.

protected void GridView1_PreRender(object sender, EventArgs e)
    {

        DataSet ds = new DataSet();

        ds = obj.select();

        GridView1.DataSource = ds;
        GridView1.DataBind();


        DataTable dt = new DataTable();
        DataRow dr;
        dt.Columns.Add("id", System.Type.GetType("System.Int32"));
        dt.Columns.Add("name", System.Type.GetType("System.String"));
        dr = dt.NewRow();
        if (GridView1.Rows.Count == 0)
        {
            dr["id"] = Convert.ToInt32("1");
            dr["name"] = "New";
        }
        else
        {
            int ct = GridView1.Rows.Count;
            int hid = Convert.ToInt32(GridView1.Rows[ct].Cells[0]);
            dr["id"] = hid + 1;
            dr["name"] = "New";
        }

        dt.Rows.Add(dr);
        dt = ds.Tables[1];
        GridView1.DataSource = ds;
        GridView1.DataBind();
        for (int i = 0; i < GridView1.Rows.Count - 1; i++)
        {
            LinkButton ln = new LinkButton();
            ln = (LinkButton)GridView1.Rows[i].Cells[2].FindControl("l1");
            ln.Visible = false;
        }
    }

In hol.cs,select method is used.

using System.Data.SqlClient;
using Majestic.Common;
public class hol:Common
{
    public DataSet select()
    {
        DataSet ds = SqlHelper.ExecuteDataset(con, CommandType.StoredProcedure, "uspselect");
        return ds;
    }
}

Note: Majestic.Common dll is used for database connectivity and manipulations.


In Grid.aspx page, I used the following code inside <body> tag.


<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" OnPreRender="GridView1_PreRender" AutoGenerateColumns="false">
        <Columns>
        <asp:TemplateField HeaderText="Id">
        <ItemTemplate>
        <%#Eval("holid")%>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="name">
        <ItemTemplate>
        <%#Eval("holname")%>
        </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
        <ItemTemplate>
        <asp:LinkButton ID="l1" runat="server">New</asp:LinkButton>
        </ItemTemplate>
        </asp:TemplateField>

        </Columns>
        </asp:GridView>

    </div>
    </form>
</body>

Can you tell if it is possible?If so, kindly give me the source code and also the guideline to solve this problem.

Thank You,
Subhashini Palanivel.


Reply With Quote
  #2 (permalink)  
Old March 28th, 2008, 12:07 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

HI there.. and what is your problem????

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add a CDATA section; add nodeset to CDATA section kssudhish XSLT 3 January 3rd, 2008 07:13 AM
Calendar Add-in Grahamski Access 4 January 4th, 2007 08:36 AM
Add Push button or Check Box in outlook add-ins capdevs VS.NET 2002/2003 0 January 7th, 2006 08:51 AM
Add In jake Excel VBA 2 March 30th, 2005 07:08 AM
C# IDE Add In shadowpug VS.NET 2002/2003 0 December 10th, 2004 11:21 AM



All times are GMT -4. The time now is 10:02 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.