Solved

Making an ASP Datagrid Fully Editable

Posted on 2009-04-08
4
437 Views
Last Modified: 2013-11-26
I've got a SQL database popluating from a form. Below that I have a datagrid that shows the contents of the database. This is simply being pulled using a sub on the VB side. I need to be able to edit the info within the datagrid.

I found plenty of examples, however some recommend a bound column, others a template column, and they're all using the itemtemplate within and that results in the following error: "validation xhtml 1.0 transitional element itemtemplate not supported"

I've removed the statement that was giving me the errors. I need someone to show me how to setup the columns so this will work.

Thanks in advance.
default.aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Theme="Theme1" Inherits="add_account_excel._Default" %>
 

<!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>Zone Manager New Department Request Form </title>

    <link href="default.css" rel="stylesheet" type="text/css" />

    <meta content="True" name="vs_snapToGrid" />

	<meta content="True" name="vs_showGrid" />

    <meta content="JavaScript" name="vs_defaultClientScript" />

</head>

<body>

    <form id="form1" method="post" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server" />

    

        <div class="header_container">

            <asp:Image ID="Logo" runat="server" ImageUrl="~/images/wfubmclogo.jpg" />

            <asp:Label ID="lblGold" runat="server" Text="zone manager"></asp:Label>

            <asp:Label ID="lblBlack" runat="server" Text="New Department Request Form"></asp:Label>     

	    </div><!-- end #header-containter -->

	    

    <div id="wrapper">
 

    <div id="content">

        <div class="main-container">

            <div id="right"> 

                <asp:Label ID="Label2" runat="server" Text="Department Name:"></asp:Label><br />

                <asp:TextBox ID="TextBox2" tabindex="2" runat="server"></asp:TextBox><br />

                <asp:Label ID="label19" runat="server" Text="Example: Dermatology" Font-Size="Smaller"></asp:Label><br /><br />

                

                <asp:Label ID="Label4" runat="server" Text="Department OU:"></asp:Label><br />

                <asp:TextBox ID="TextBox4" tabindex="4" runat="server"></asp:TextBox><br />

                <asp:Label ID="label21" runat="server" Text="Example: Derm_1530_Dermatology" Font-Size="Smaller"></asp:Label><br /><br />

              

                <asp:Label ID="Label6" runat="server" Text="Groups:"></asp:Label><br />

                <asp:TextBox ID="TextBox6" tabindex="6" runat="server"></asp:TextBox><br />

                <asp:Label ID="label23" runat="server" Text="Example: Dermatology" Font-Size="Smaller"></asp:Label><br /><br />

                          

                <asp:Label ID="Label8" runat="server" Text="Admin Contact Phone:"></asp:Label><br />

                <asp:TextBox ID="TextBox8" tabindex="8" runat="server"></asp:TextBox><br /><br />

               

                <asp:Label ID="Label10" runat="server" Text="Zone Manager:"></asp:Label><br />

                <asp:TextBox ID="TextBox10" tabindex="10" runat="server"></asp:TextBox><br /><br />  

                <div class="right-container">Right</div>

            </div> <!-- end #right -->    

                        

             <div id="left">  

                <asp:Label ID="Label1" runat="server" Text="Department Number:"></asp:Label><br />

                <asp:TextBox ID="TextBox1" tabindex="1" runat="server"></asp:TextBox><br />

                <asp:Label ID="label18" runat="server" Text="Example: 153000" Font-Size="Smaller"></asp:Label><br /><br />

                

                <asp:Label ID="Label3" runat="server" Text="Institution OU:"></asp:Label><br />

                <asp:TextBox ID="TextBox3" tabindex="3" runat="server"></asp:TextBox><br />

                <asp:Label ID="label20" runat="server" Text="Example: School or Hospital" Font-Size="Smaller"></asp:Label><br /><br />

                

                <asp:Label ID="Label5" runat="server" Text="Home Directory Location:"></asp:Label><br />

                <asp:TextBox ID="TextBox5" tabindex="5" runat="server"></asp:TextBox><br />

                <asp:Label ID="label22" runat="server" Text="Example: \\csb1\csderm$" Font-Size="Smaller"></asp:Label><br /><br />

                

                <asp:Label ID="Label7" runat="server" Text="Admin Contact Name:"></asp:Label><br />

                <asp:TextBox ID="TextBox7" tabindex="7" runat="server"></asp:TextBox><br /><br />

                

                <asp:Label ID="Label9" runat="server" Text="Admin Contact Email:"></asp:Label><br />

                <asp:TextBox ID="TextBox9" tabindex="9" runat="server"></asp:TextBox><br /><br />    

                <div class="left-container">LEFT</div>   

            </div> <!-- end #left-->    

        </div> <!-- end class main-container -->   

        

        <div class="bottom-container">            

                <div class="label-container"> 

                    <asp:Label ID="lblResults" runat="server"></asp:Label>                

                </div> <!-- end class label-container -->

                                

                <div class="image-container"> 

                    <asp:Image ID="imgCheckMark" runat="server" 

                        ImageUrl="~/images/checkmark_Bold_Brush_Green.png" Height="30px"/>

                    <asp:Image ID="imgRedX" runat="server" ImageUrl="~/images/red_X.jpg" Height="30px"/>

                </div><!-- end class image container --> 			

            

                <div class="button-container">

                    <asp:Button ID="Clear" tabindex="-1" runat="server" Text="Clear" />

                    <asp:Button ID="Submit" tabindex="-1" runat="server" Text="Submit" />

                    <asp:Button ID="View" tabindex="-1" runat="server" Text="View File" />

                </div><!-- end button-container -->                

        </div> <!-- end class bottom-container -->          

            

        

   </div><!-- end #content -->
 

	        <div id="footer">

                <asp:Label ID="Label17" runat="server" Text="  Requested by:  "></asp:Label>

                <asp:Label ID="Label16" runat="server"></asp:Label><br /><br /><br />

	        </div> 

</div><!-- end #wrapper -->	        

	     <div class="datagrid-container">

	       <div>

                <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 10px;"

				runat="server" ForeColor="Black" ShowFooter="True" CellPadding="4" 

                BackColor="White" BorderWidth="1px"

				BorderStyle="None" BorderColor="#CCCCCC" Height="135px" >

				<SelectedItemStyle Font-Bold="True" Wrap="False" ForeColor="White" BackColor="#CC3333"></SelectedItemStyle>

				<EditItemStyle Wrap="False"></EditItemStyle>

				<AlternatingItemStyle Font-Bold="True" Wrap="False" ForeColor="Black" BackColor="#CCCC99"></AlternatingItemStyle>

				<ItemStyle Wrap="False"></ItemStyle>

				<HeaderStyle Font-Bold="True" Wrap="False" ForeColor="White" BackColor="#333333"></HeaderStyle>

				<FooterStyle Wrap="False" ForeColor="White" BackColor="#333333"></FooterStyle>

				<Columns>

				    <asp:ButtonColumn Text="Edit" CommandName="Edit"></asp:ButtonColumn>

				</Columns>

				<PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="White" Wrap="False"></PagerStyle>

		        </asp:datagrid>

		    </div> 

		  </div> <!-- end datagrid-container --> 

               

    </form>

</body>

</html>

default.aspx.vb

Imports System

Imports System.Data

Imports System.Data.OleDb

Imports System.Data.SqlClient

Imports System.DirectoryServices

Imports System.Collections

Imports System.Collections.Specialized
 

Namespace add_account_excel
 

    Partial Public Class _Default

        Inherits System.Web.UI.Page

        Dim strUser As String

        Dim strDate As String

        Dim DS As System.Data.DataSet
 

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            lblResults.Visible = False

            imgCheckMark.Visible = False

            imgRedX.Visible = False

            strUser = (Request.ServerVariables("AUTH_USER"))
 

            If InStr(strUser, "domain\") Then

                strUser = Replace(strUser, "domain\", "")

            End If
 

            If InStr(strUser, "domain\") Then

                strUser = Replace(strUser, "domain\", "")

            End If
 

            Label16.Text = strUser
 

            Call getDatafromfile()

        End Sub
 

        Sub getDatafromfile()

            Dim sConn As SqlConnection

            Dim sComm As SqlCommand

            Dim sAdapt As SqlDataAdapter
 

            sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)

            sComm = New SqlCommand("select * from Automated_ZM_Dept_Request", sConn)

            sAdapt = New SqlDataAdapter(sComm)

            sConn.Open()
 

            DS = New DataSet

            sAdapt.Fill(DS)

            DataGrid1.DataSource = DS

            DataGrid1.DataBind()

            sConn.Close()

        End Sub
 

        Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click

            Dim strDate As String

            strDate = DateString & "@" & TimeString
 

            If TextBox1.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Department ID'"

            ElseIf TextBox2.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Department Name'"

            ElseIf TextBox3.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Institution OU'"

            ElseIf TextBox4.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Department OU'"

            ElseIf TextBox5.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Home Directory Location'"

            ElseIf TextBox6.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Groups'"

            ElseIf TextBox7.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Admin Contact'"

            ElseIf TextBox8.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Phone Number'"

            ElseIf TextBox9.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Contact Email'"

            ElseIf TextBox10.Text = "" Then

                lblResults.Visible = True

                imgCheckMark.Visible = False

                imgRedX.Visible = True

                lblResults.Text = "Please enter 'Zone Manager'"

            Else

                lblResults.Visible = True

                imgCheckMark.Visible = True

                imgRedX.Visible = False

                lblResults.Text = "New Department Request Submitted"

                Call Add_SQL()

            End If
 

        End Sub
 

        Public Sub Add_SQL()
 

            Dim sConn As Data.SqlClient.SqlConnection

            Dim sComm As Data.SqlClient.SqlCommand

            Dim sAdapt As Data.SqlClient.SqlDataAdapter
 

            sConn = New Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnection").ConnectionString)

            sComm = New Data.SqlClient.SqlCommand("INSERT INTO Automated_ZM_Dept_Request (DeptID, Dept, DeptOU, InstOU, HomeDir, Groups, Contact, Phone, Email, ZoneMgr, Submitted, Requestor) VALUES ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & strDate & "','" & strUser & "')", sConn)

            sAdapt = New Data.SqlClient.SqlDataAdapter(sComm)

            sConn.Open()

            sComm.ExecuteNonQuery()

            sConn.Close()
 

            clrFields()

            getDatafromfile()

        End Sub
 

        Sub clrFields()

            TextBox1.Text = ""

            TextBox2.Text = ""

            TextBox3.Text = ""

            TextBox4.Text = ""

            TextBox5.Text = ""

            TextBox6.Text = ""

            TextBox7.Text = ""

            TextBox8.Text = ""

            TextBox9.Text = ""

            TextBox10.Text = ""

            lblResults.Visible = True

            imgCheckMark.Visible = True

            imgRedX.Visible = False

            lblResults.Text = "New Department Request Submitted"
 

        End Sub
 

        Protected Sub Clear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Clear.Click

            TextBox1.Text = ""

            TextBox2.Text = ""

            TextBox3.Text = ""

            TextBox4.Text = ""

            TextBox5.Text = ""

            TextBox6.Text = ""

            TextBox7.Text = ""

            TextBox8.Text = ""

            TextBox9.Text = ""

            TextBox10.Text = ""

            lblResults.Visible = False

            imgCheckMark.Visible = False

            imgRedX.Visible = False
 

        End Sub
 

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles View.Click

            lblResults.Text = Nothing

            getDatafromfile()

        End Sub

  End Class

End Namespace

Open in new window

0
Comment
Question by:JB4375
  • 2
  • 2
4 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 500 total points
Comment Utility
You've got a scriptmanager control and your codebehind is a partial class...both these lead me to believe you are using ASP.Net 2.0 correct?

If yes, then you should be using a Gridview control and not a datagrid control.
There is a big difference between the controls and probably the root of your problems.
The GridView replaced the Datagrid for ASP.Net 2.0+
0
 
LVL 1

Author Comment

by:JB4375
Comment Utility
ASP. Net 2.0 is correct.
That's funny because I actually started with gridview, and then after some research, the examples I saw were using datagrid. I changed it after coming to the obviously incorrect conclusion that gridview meant just that: viewing, not accessing.
Thanks!!
0
 
LVL 37

Expert Comment

by:samtran0331
Comment Utility
When you say "Fully Editable"...do you want the entire grid (all rows) to update with one button click, or for each row to have an "edit/save" feature?...I might be able to help you find a better tutorial/walkthrough...
0
 
LVL 1

Author Comment

by:JB4375
Comment Utility
I think each row should have the edit/save feature. The idea is that they will use the form to submit new departments. In the event that some information changes they will use the data grid to edit contact information, or whatever, for that department.
 
 
 
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now