Solved

Gridview rows

Posted on 2008-06-23
5
453 Views
Last Modified: 2012-06-21
Hi Guys

I have a gridview which has Dataset as datasourse. this sql query on page load will return empty dataset. the code below will generate the first emty row.

I need to be able to click on the Add New link button and rather have the data entered in the textbox be part of the gridview as well as create another emtyp row. this can happen 'n' number of times.
I need to preserve the data from initial entries.




<EmptyDataTemplate>
                <table><tr>
                <td><asp:TextBox ID="txtGoals" runat="server" Columns="10"></asp:TextBox></td>
                <td><asp:TextBox ID="txttactics" runat="server" Columns="10"></asp:TextBox></td>
                <td><asp:TextBox ID="txtResources" runat="server" Columns="10"></asp:TextBox></td>
                <td><asp:TextBox ID="txtOwner" runat="server" Columns="10"></asp:TextBox></td>
                <td><asp:TextBox ID="txtTarget" runat="server" Columns="10"></asp:TextBox></td>
                <td><asp:TextBox ID="txtSd" runat="server" Columns="10"></asp:TextBox></td>
                <td><asp:TextBox ID="txtfd" runat="server" Columns="10"></asp:TextBox></td>
                <td><asp:LinkButton ID="LinkButton3" runat="server" CommandName="AddNew" ForeColor="#FF8000"
                                Width="50px">Add New</asp:LinkButton></td>
                </tr></table>
                </EmptyDataTemplate>

Open in new window

0
Comment
Question by:Mayank_Agarwal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Expert Comment

by:MrAgile
ID: 21861399
0
 
LVL 1

Accepted Solution

by:
Mayank_Agarwal earned 0 total points
ID: 21861430
When i CLick on the or insert button on the gridview i dont want it go in the database. I want it to be inserted as row. then have one SAVE button which saves the whole form.
0
 
LVL 8

Expert Comment

by:MrAgile
ID: 21862636
No problem.

 >>then have one SAVE button which saves the whole form. to what? a database, file??

Also it maybe be helpful if you post WORKING source code with an xml datasource so I can have a look at the page itself.
0
 
LVL 1

Author Comment

by:Mayank_Agarwal
ID: 21862785
Hi
To the database using sperate stored procedures etc.


.....header stuff.......                    
<asp:TemplateField HeaderText="Owner">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtOwner" runat="server" Columns="35" Text='<%# Bind("Owner") %>'
                                TextMode="MultiLine"></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtOwner" runat="server" Columns="15"></asp:TextBox>
                        </FooterTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblOwner" runat="server" Text='<%# Bind("Owner") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Start Date">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtStartDateEdit" runat="server" Columns="35" Text='<%# Bind("StartDate") %>'
                                TextMode="MultiLine"></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtStartDateIns" runat="server" Columns="10"></asp:TextBox>
                        </FooterTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblStartDate" runat="server" Text='<%# Bind("StartDate") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Finish Date">
                        <EditItemTemplate>
                            <asp:TextBox ID="txtFinishDate" runat="server" Columns="35" Text='<%# Bind("FinishDate") %>'
                                TextMode="MultiLine"></asp:TextBox>
                        </EditItemTemplate>
                        <FooterTemplate>
                            <asp:TextBox ID="txtFinishDate" runat="server" Columns="10"></asp:TextBox>
                        </FooterTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblFinishDate" runat="server" Text='<%# Bind("FinishDate") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Edit" ShowHeader="False">
                        <EditItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                Text="Update" ValidationGroup="partUpdate"></asp:LinkButton>
                            <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                Text="Cancel"></asp:LinkButton>
                        </EditItemTemplate>
                        <FooterTemplate>
                            &nbsp;<asp:LinkButton ID="LinkButton3" runat="server" CommandName="AddNew" ForeColor="#FF8000"
                                ValidationGroup="AddAnn" Width="50px">Save Plan</asp:LinkButton>
                        </FooterTemplate>
                        <ItemTemplate>
                            <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                Text="Edit"></asp:LinkButton>
                        </ItemTemplate>
                        <ControlStyle ForeColor="#FF8000" />
                    </asp:TemplateField>
                    <asp:CommandField CausesValidation="False" ShowDeleteButton="True">
                        <ControlStyle ForeColor="#FF8000" />
                    </asp:CommandField>
                </Columns>
 
            </asp:GridView>
 
 
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
           Using myconn As New SqlConnection(connStr)
                Dim cmd As New SqlCommand("select * from PlanDetails where plandetailsID = '999999'", myconn) 'THIS IS A JUNK ENTRY SO 
'THAT I CAN GET THE FOOTER TO SHOW UP. I HAVE TRIED EMPTYTEMPLATE 
'BUT THAT WASNT VERY PRETTY.
                Dim da As New SqlDataAdapter(cmd)
                myconn.Open()
                da.Fill(ds)
                ds.Dispose()
 
                If ds.Tables(0).Rows.Count = 0 Then
                    ds.Tables(0).Rows.Add(ds.Tables(0).NewRow)
                    GridView1.DataSource = ds
                    GridView1.DataBind()
                    Dim columnCount As Integer
                    columnCount = GridView1.Rows(0).Cells.Count
                    GridView1.Rows(0).Cells.Clear()
                    GridView1.Rows(0).Cells.Add(New TableCell)
                    GridView1.Rows(0).Cells(0).ColumnSpan = columnCount
                    GridView1.Rows(0).Cells(0).Text = "Please insert new Plan Details."
                Else
                    GridView1.DataSource = ds
                    GridView1.DataBind()
                End If
End Using

Open in new window

0
 
LVL 8

Expert Comment

by:MrAgile
ID: 21862845
Hi There,

Please post the entire source code. I suggest that you just dummy up some xml as a datasource.

Sean
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 54
Data Analysis 7 59
asp.net mvc5 6 34
Trying to check to see if email is in valid format in asp.net 3 25
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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