C#.NET - Input String not in a Valid Format

scross1276
scross1276 used Ask the Experts™
on
I worked through the weekend at a feable attempt to resolve this error.  I've posted the entire code for the page involved below, both .aspx and code behind.  I wish I could give you 5,000 points for solving it as it's worth that too me, darn limit.

Anyway, I got this code from an example out of the ADO.NET 3.5 Cookbook put out by O'Reilly.  The major difference between my code and theirs is that I'm grabbing the needed record from the id provided in the querystring and they don't.  EE wouldn't let me attach their sample, but you can download it here - http://examples.oreilly.com/9780596101404/ADO.NET3.5ckbk_csharp_source.zip.  It's the 8.7 UpdateDataWebFormGridView solution.

I get the "Input string not in a valid format" error anytime I do a function that involves changing the database.  (e.g. When I try to edit a row, it fails on the DataRow row = dt.Rows.Find(((TextBox)... line in my gvRevealDetails_RowUpdating constructor.)  After stepping through my code, it appears that it is never filling the "rows" attribute for the update, but I have verified that it is connecting to the database and pulling the existing data back, so it's something with the code that it doesn't appear to be saving the changes to the datatable to send back to the database.

You'll notice a section that isn't in the datagrid, that's additional data needed for the page outside of the O'Reilly datagrid example.  It works fine.

Please, please, please, please help me out!!!
.aspx:
 
 
<%@ Register TagPrefix="uc1" TagName="menu" Src="~/menu.ascx" %>
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="updateReveal.aspx.cs" Inherits="eForms.updateReveal" %>
 
<!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>Update Reveal Request</title>
    <link rel="stylesheet" type="text/css" href="../site.css" />
    <link rel="stylesheet" type="text/css" href="../print.css" />
</head>
<body>
    <form id="form1" method="post" runat="server">
    <uc1:menu ID="Menu" runat="server"></uc1:menu>
    <div id="content">
        <br />
        <div class="header1">
            Information Technology</div>
        <div class="header2">
            Pending ManMan / Reveal Reports Request for
            <asp:Label ID="lblUser" runat="server" />
        </div>
        <br />
        <br />
        <asp:Table ID="tblRevealInfo" runat="server" CellSpacing="2" Width="675" BorderWidth="0">
            <asp:TableRow>
                <asp:TableCell Width="400px">
                    Date of Request:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblRequestDate" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Requestor:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblRequestor" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Employee Name Needing Access:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblName" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Network ID of Employee Needing Access:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblID" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Position / Location:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblPositionLocation" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Salesman # (if applicable):
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblSalesman" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    User to Duplicate Access of
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblMirror" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Approving Supervisor:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblApprovingSupervisor" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
        <br />
        <br />
        <asp:GridView ID="gvRevealDetails" runat="server" OnRowEditing="gvRevealDetails_RowEditing"
            OnRowCancelingEdit="gvRevealDetails_RowCancelingEdit" OnRowCommand="gvRevealDetails_RowCommand"
            OnRowDeleting="gvRevealDetails_RowDeleting" OnRowUpdating="gvRevealDetails_RowUpdating"
            AutoGenerateColumns="false" Width="725px" ShowFooter="true">
            <Columns>
                <asp:TemplateField HeaderText="Edit" ShowHeader="false">
                    <EditItemTemplate>
                        <asp:LinkButton ID="lbUpdate" runat="server" Text="Update" CausesValidation="true"
                            CommandName="Update" />
                        <asp:LinkButton ID="lbCancel" runat="server" Text="Cancel" CausesValidation="false"
                            CommandName="Cancel" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="lbEdit" runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" />
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:LinkButton ID="lbAdd" runat="server" CommandName="AddNew" Text="Add New" CausesValidation="false" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:CommandField HeaderText="Delete" ShowDeleteButton="true" ShowHeader="true" />
                <asp:TemplateField HeaderText="id" Visible="false">
                    <ItemTemplate>
                        <asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewIDTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="name">
                    <ItemTemplate>
                        <asp:Label ID="lblReportName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtReportName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewReportNameTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="description">
                    <ItemTemplate>
                        <asp:Label ID="lblReportDescription" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.description") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtReportDescription" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.description") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewReportDescriptionTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="freq">
                    <ItemTemplate>
                        <asp:Label ID="lblFrequency" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.freq") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlFrequency" runat="server" DataTextField='<%# DataBinder.Eval(Container, "DataItem.freq") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.freq") %>'>
                            <asp:ListItem id="liFreq0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFreq1" runat="server" Value="1">Daily</asp:ListItem>
                            <asp:ListItem id="liFreq2" runat="server" Value="2">Weekly</asp:ListItem>
                            <asp:ListItem id="liFreq3" runat="server" Value="3">Monthly</asp:ListItem>
                            <asp:ListItem id="liFreq4" runat="server" Value="4">Quarterly</asp:ListItem>
                            <asp:ListItem id="liFreq5" runat="server" Value="5">Annually</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewFrequencyDDL" runat="server">
                            <asp:ListItem id="liFreq0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFreq1" runat="server" Value="1">Daily</asp:ListItem>
                            <asp:ListItem id="liFreq2" runat="server" Value="2">Weekly</asp:ListItem>
                            <asp:ListItem id="liFreq3" runat="server" Value="3">Monthly</asp:ListItem>
                            <asp:ListItem id="liFreq4" runat="server" Value="4">Quarterly</asp:ListItem>
                            <asp:ListItem id="liFreq5" runat="server" Value="5">Annually</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="db">
                    <ItemTemplate>
                        <asp:Label ID="lblDatabase" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.db") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlDatabase" runat="server" DataTextField='<%# DataBinder.Eval(Container, "DataItem.db") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.db") %>'>
                            <asp:ListItem id="liDb0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liDb1" runat="server" Value="1">10-TMP</asp:ListItem>
                            <asp:ListItem id="liDb2" runat="server" Value="2">15-TMP LIFO</asp:ListItem>
                            <asp:ListItem id="liDb3" runat="server" Value="3">30-PPD</asp:ListItem>
                            <asp:ListItem id="liDb4" runat="server" Value="4">35-PPD LIFO</asp:ListItem>
                            <asp:ListItem id="liDb5" runat="server" Value="5">Inovice File</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewDatabaseDDL" runat="server">
                            <asp:ListItem id="liDb0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liDb1" runat="server" Value="1">10-TMP</asp:ListItem>
                            <asp:ListItem id="liDb2" runat="server" Value="2">15-TMP LIFO</asp:ListItem>
                            <asp:ListItem id="liDb3" runat="server" Value="3">30-PPD</asp:ListItem>
                            <asp:ListItem id="liDb4" runat="server" Value="4">35-PPD LIFO</asp:ListItem>
                            <asp:ListItem id="liDb5" runat="server" Value="5">Inovice File</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="format">
                    <ItemTemplate>
                        <asp:Label ID="lblFormat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.format") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlFormat" runat="server" AppendDataBoundItems="true" DataTextField='<%# DataBinder.Eval(Container, "DataItem.format") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.format") %>'>
                            <asp:ListItem id="liFormat0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFormat1" runat="server" Value="1">Print</asp:ListItem>
                            <asp:ListItem id="liFormat2" runat="server" Value="2">Reveal</asp:ListItem>
                            <asp:ListItem id="liFormat3" runat="server" Value="3">Both</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewFormatDDL" runat="server">
                            <asp:ListItem id="liFormat0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFormat1" runat="server" Value="1">Print</asp:ListItem>
                            <asp:ListItem id="liFormat2" runat="server" Value="2">Reveal</asp:ListItem>
                            <asp:ListItem id="liFormat3" runat="server" Value="3">Both</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
 
 
 
 
 
 
C#.NET Code Behind
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;
using System.DirectoryServices;
using System.Drawing;
 
namespace eForms
{
    public partial class updateReveal : System.Web.UI.Page
    {
        private SqlConnection myConnection;
        private int qsID;
        private string sqlSelect = "";
 
 
        public string GetUserName()
        {
            string retVal = string.Empty;
            string uname = User.Identity.Name.Split('\\')[1];
 
            DirectoryEntry userEntry = new DirectoryEntry("WinNT://domain/" + uname);
            retVal = (string)userEntry.Properties["fullname"].Value;
            return retVal;
        }
 
 
        protected void Page_Load(object sender, EventArgs e)
        {
            qsID = Int32.Parse(Request.QueryString["id"]);
 
            if (!Page.IsPostBack)
            {
                myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conForms"].ConnectionString);
                myConnection.Open();
 
                string sqlReveal = "select * from table where id = " + qsID;
 
                SqlCommand cmdReveal = new SqlCommand(sqlReveal, myConnection);
                SqlDataReader sdrReveal = cmdReveal.ExecuteReader(CommandBehavior.SingleRow);
 
                if (sdrReveal.Read())
                {
                    lblUser.Text = sdrReveal["newUser"].ToString();
                    lblRequestDate.Text = sdrReveal["requestDate"].ToString();
                    lblRequestor.Text = sdrReveal["requestedBy"].ToString();
                    lblName.Text = sdrReveal["newUser"].ToString();
                    lblID.Text = sdrReveal["newUserid"].ToString();
                    lblPositionLocation.Text = sdrReveal["positionLocation"].ToString();
                    lblSalesman.Text = sdrReveal["salesman"].ToString();
                    lblMirror.Text = sdrReveal["userMirror"].ToString();
                    lblApprovingSupervisor.Text = sdrReveal["approvingSupervisor"].ToString();
                }
                sdrReveal.Close();
 
 
                gvRevealDetails.DataSource = LoadData();
                gvRevealDetails.DataKeyNames = new string[] { "id" };
                gvRevealDetails.DataBind();
            }
        }
 
        protected DataTable LoadData()
        {
            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conForms"].ConnectionString);
            myConnection.Open();
 
            sqlSelect = "select id, rid, name, description, freq, db, format from table2 where rid = " + qsID;
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, myConnection);
 
            DataTable dt = new DataTable();
            da.FillSchema(dt, SchemaType.Source);
            da.Fill(dt);
 
            Session["GridViewDataTable"] = dt;
            return dt;
 
        }
 
        private void UpdateDataSource(DataTable dt)
        {
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, myConnection);
            SqlCommandBuilder cb = new SqlCommandBuilder(da);
            da.Update(dt);
 
            Session["GridViewDataTable"] = dt;
        }
 
        private void BindDataGrid()
        {
            DataTable dt = ((DataTable)Session["GridViewDataTable"]);
 
            gvRevealDetails.DataSource = dt;
            gvRevealDetails.DataBind();
        }
 
        protected void gvRevealDetails_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
        {
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }
 
        protected void gvRevealDetails_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddNew"))
            {
                DataTable dt = (DataTable)Session["GridViewDataTable"];
 
                DataRow dr = dt.NewRow();
 
                dr["id"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewIDTextBox")).Text;
                dr["name"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportNameTextBox")).Text;
                dr["description"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportDescriptionTextBox")).Text;
                dr["freq"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFrequencyDDL")).Text;
                dr["db"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewDatabaseDDL")).Text;
                dr["format"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFormatDDL")).Text;
 
                dt.Rows.Add(dr);
                UpdateDataSource(dt);
 
                BindDataGrid();
            }
        }
 
        protected void gvRevealDetails_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
            int id = (int)gvRevealDetails.DataKeys[e.RowIndex].Value;
            dt.Rows.Find(id).Delete();
 
            UpdateDataSource(dt);
            BindDataGrid();
        }
 
        protected void gvRevealDetails_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
        {
            gvRevealDetails.EditIndex = e.NewEditIndex;
 
            BindDataGrid();
        }
 
        protected void gvRevealDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
            DataRow row =
                dt.Rows.Find(((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtID")).Text);
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }
    }
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
problem is in  event protected void gvRevealDetails_RowUpdating


                DataRow row = dt.Rows.Find(int.Parse(((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtID")).Text));

your id column might have datatype of integer. so try to convert string to integer.



protected void gvRevealDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
            DataRow row =
                DataRow row = dt.Rows.Find(int.Parse(((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtID")).Text));
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }

Open in new window

Author

Commented:
Great idea, and you're right, my id column is an int, but I still get the same error on the same line, which is the line you're looking at right now.

Commented:
Can you please give detail of each column datatype ?

what is value in txtID field ?

Still error on same line ? if so print screen in debug mode and attach image ?

TRy to check value of txtID ?

            DataTable dt = (DataTable)Session["GridViewDataTable"]; 
            DataRow row = dt.Rows.Find(int.Parse(((TextBox)e.Row.FindControl("txtID")).Text.Trim()));
            row["name"] =  ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFormat")).Text;

Open in new window

CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

Author

Commented:
I'm going to go look at the link you posted now, but I wanted to post the screenshot.  I can't hover over txtID and get a value in debug mode, so I posted the error deriving from stepping through it to try.
image.jpg

Commented:
now check what is value of text in debug mode.

 DataTable dt = (DataTable)Session["GridViewDataTable"]; 
 string text = ((TextBox)e.Row.FindControl("txtID")).Text.Trim();
            DataRow row = dt.Rows.Find(int.Parse(((TextBox)e.Row.FindControl("txtID")).Text.Trim()));
            row["name"] =  ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFormat")).Text;

Open in new window

Author

Commented:
I get a build error on the "Row" property in the string text line and the datarow row line in that code.  The error is:

Error      2      'System.Web.UI.WebControls.GridViewUpdateEventArgs' does not contain a definition for 'Row' and no extension method 'Row' accepting a first argument of type 'System.Web.UI.WebControls.GridViewUpdateEventArgs' could be found (are you missing a using directive or an assembly reference?)      C:\Inetpub\wwwroot\eForms\eForms\reveal\updateReveal.aspx.cs      163      39      eforms

Author

Commented:
I changed it from Row to RowIndex, then got this...  (It's on the FindControl method in the same two lines.)

Error      2      'int' does not contain a definition for 'FindControl' and no extension method 'FindControl' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)      C:\Inetpub\wwwroot\eForms\eForms\reveal\updateReveal.aspx.cs      163      48      eforms

Commented:

now check text value in debug mode ?

verifty that is that contain proper id value or it is emply text ?

protected void gvRevealDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
    string text =  ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtID")).Text;
                DataRow row = dt.Rows.Find(int.Parse(((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtID")).Text));
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }

Open in new window

Author

Commented:
Nothing there...
image.jpg

Commented:

protected void gvRevealDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
 
            DataRow row = dt.Rows.Find(int.Parse(e.Keys["ID"].ToString()));
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }

Open in new window

Commented:
is this work ?

Author

Commented:
The good news is that the previous error is gone, but now it's saying an object reference is not set to an instance of an object.
image.jpg

Author

Commented:
Any ideas on the new error??

Commented:
i used ID  in e.Keys["ID"]  so used e.Keys["id"]

protected void gvRevealDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
 
            DataRow row = dt.Rows.Find(int.Parse(e.Keys["id"].ToString()));
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[e.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[e.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }

Open in new window

Author

Commented:
I saw that and changed it a little bit ago.  No change on the result though.  I still get the object reference error.

Commented:
DataRow row = dt.Rows.Find(int.Parse(e.OldValues["id"].ToString()));

Author

Commented:
Same error, same line.

See why I was ready to drive over my computer this past weekend?

Commented:
Hello,

can you use RowCommand to update ?

just remove row_updating and try attached code in row_command.

 protected void gvRevealDetails_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("AddNew"))
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
            DataRow dr = dt.NewRow();
 
            dr["id"] =
                ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewIDTextBox")).Text;
            dr["name"] =
                ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportNameTextBox")).Text;
            dr["description"] =
                ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportDescriptionTextBox")).Text;
            dr["freq"] =
                ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFrequencyDDL")).Text;
            dr["db"] =
                ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewDatabaseDDL")).Text;
            dr["format"] =
                ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFormatDDL")).Text;
 
            dt.Rows.Add(dr);
            UpdateDataSource(dt);
 
            BindDataGrid();
        }
        else if (e.CommandName.Equals("Update"))
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
            LinkButton lnk = e.CommandSource as LinkButton;
            GridViewRow grow = lnk.NamingContainer as GridViewRow;
            DataRow row = dt.Rows.Find(int.Parse(((TextBox)gvRevealDetails.Rows[grow.RowIndex].FindControl("txtID")).Text));
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[grow.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[grow.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }
    }

Open in new window

Author

Commented:
Can't do that either.  I get the following error when rendering the page...

No overload for 'gvRevealDetails_RowCommand' matches delegate 'System.Web.UI.WebControls.GridViewEditEventHandler'

Commented:
then just not use rowcommand event for update .

can you update in this method ? i tihkn primary key is missing .

if not....

Make Visible="true" for column id . See it is work or not.

 protected DataTable LoadData()
        {
            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conForms"].ConnectionString);
            myConnection.Open();
 
            sqlSelect = "select id, rid, name, description, freq, db, format from table2 where rid = " + qsID;
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, myConnection);
 
            DataTable dt = new DataTable();
            da.FillSchema(dt, SchemaType.Source);
            da.Fill(dt);
             dt.PrimaryKey = new DataColumn[] { dt.Columns["id"] };
            Session["GridViewDataTable"] = dt;
            return dt;
 
        }

Open in new window

Author

Commented:
That didn't work either, however you're correct, the id column is blank, so that's defintely the problem.

Author

Commented:
I just did a debug on the LoadData() constructor and stepped through it.  The id field is being read in, so we're losing it somewhere.

Commented:
I made few change .

1. Remove row updating event. ( aspx and codebehind)

2. Attach id to command argument of LinkButton of Update

3. Add new code RowCommand to handle the update.

debug and test this.

.aspx:
 
 
<%@ Register TagPrefix="uc1" TagName="menu" Src="~/menu.ascx" %>
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="updateReveal.aspx.cs" Inherits="eForms.updateReveal" %>
 
<!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>Update Reveal Request</title>
    <link rel="stylesheet" type="text/css" href="../site.css" />
    <link rel="stylesheet" type="text/css" href="../print.css" />
</head>
<body>
    <form id="form1" method="post" runat="server">
    <uc1:menu ID="Menu" runat="server"></uc1:menu>
    <div id="content">
        <br />
        <div class="header1">
            Information Technology</div>
        <div class="header2">
            Pending ManMan / Reveal Reports Request for
            <asp:Label ID="lblUser" runat="server" />
        </div>
        <br />
        <br />
        <asp:Table ID="tblRevealInfo" runat="server" CellSpacing="2" Width="675" BorderWidth="0">
            <asp:TableRow>
                <asp:TableCell Width="400px">
                    Date of Request:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblRequestDate" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Requestor:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblRequestor" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Employee Name Needing Access:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblName" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Network ID of Employee Needing Access:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblID" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Position / Location:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblPositionLocation" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Salesman # (if applicable):
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblSalesman" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    User to Duplicate Access of
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblMirror" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Approving Supervisor:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblApprovingSupervisor" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
        <br />
        <br />
        <asp:GridView ID="gvRevealDetails" runat="server" OnRowEditing="gvRevealDetails_RowEditing"
            OnRowCancelingEdit="gvRevealDetails_RowCancelingEdit" OnRowCommand="gvRevealDetails_RowCommand"
            OnRowDeleting="gvRevealDetails_RowDeleting"
            AutoGenerateColumns="false" Width="725px" ShowFooter="true">
            <Columns>
                <asp:TemplateField HeaderText="Edit" ShowHeader="false">
                    <EditItemTemplate>
                        <asp:LinkButton ID="lbUpdate" runat="server" Text="Update" CausesValidation="true"
                            CommandName="Update" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                        <asp:LinkButton ID="lbCancel" runat="server" Text="Cancel" CausesValidation="false"
                            CommandName="Cancel" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="lbEdit" runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" />
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:LinkButton ID="lbAdd" runat="server" CommandName="AddNew" Text="Add New" CausesValidation="false" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:CommandField HeaderText="Delete" ShowDeleteButton="true" ShowHeader="true" />
                <asp:TemplateField HeaderText="id" Visible="false">
                    <ItemTemplate>
                        <asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewIDTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="name">
                    <ItemTemplate>
                        <asp:Label ID="lblReportName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtReportName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewReportNameTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="description">
                    <ItemTemplate>
                        <asp:Label ID="lblReportDescription" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.description") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtReportDescription" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.description") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewReportDescriptionTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="freq">
                    <ItemTemplate>
                        <asp:Label ID="lblFrequency" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.freq") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlFrequency" runat="server" DataTextField='<%# DataBinder.Eval(Container, "DataItem.freq") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.freq") %>'>
                            <asp:ListItem id="liFreq0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFreq1" runat="server" Value="1">Daily</asp:ListItem>
                            <asp:ListItem id="liFreq2" runat="server" Value="2">Weekly</asp:ListItem>
                            <asp:ListItem id="liFreq3" runat="server" Value="3">Monthly</asp:ListItem>
                            <asp:ListItem id="liFreq4" runat="server" Value="4">Quarterly</asp:ListItem>
                            <asp:ListItem id="liFreq5" runat="server" Value="5">Annually</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewFrequencyDDL" runat="server">
                            <asp:ListItem id="liFreq0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFreq1" runat="server" Value="1">Daily</asp:ListItem>
                            <asp:ListItem id="liFreq2" runat="server" Value="2">Weekly</asp:ListItem>
                            <asp:ListItem id="liFreq3" runat="server" Value="3">Monthly</asp:ListItem>
                            <asp:ListItem id="liFreq4" runat="server" Value="4">Quarterly</asp:ListItem>
                            <asp:ListItem id="liFreq5" runat="server" Value="5">Annually</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="db">
                    <ItemTemplate>
                        <asp:Label ID="lblDatabase" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.db") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlDatabase" runat="server" DataTextField='<%# DataBinder.Eval(Container, "DataItem.db") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.db") %>'>
                            <asp:ListItem id="liDb0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liDb1" runat="server" Value="1">10-TMP</asp:ListItem>
                            <asp:ListItem id="liDb2" runat="server" Value="2">15-TMP LIFO</asp:ListItem>
                            <asp:ListItem id="liDb3" runat="server" Value="3">30-PPD</asp:ListItem>
                            <asp:ListItem id="liDb4" runat="server" Value="4">35-PPD LIFO</asp:ListItem>
                            <asp:ListItem id="liDb5" runat="server" Value="5">Inovice File</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewDatabaseDDL" runat="server">
                            <asp:ListItem id="liDb0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liDb1" runat="server" Value="1">10-TMP</asp:ListItem>
                            <asp:ListItem id="liDb2" runat="server" Value="2">15-TMP LIFO</asp:ListItem>
                            <asp:ListItem id="liDb3" runat="server" Value="3">30-PPD</asp:ListItem>
                            <asp:ListItem id="liDb4" runat="server" Value="4">35-PPD LIFO</asp:ListItem>
                            <asp:ListItem id="liDb5" runat="server" Value="5">Inovice File</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="format">
                    <ItemTemplate>
                        <asp:Label ID="lblFormat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.format") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlFormat" runat="server" AppendDataBoundItems="true" DataTextField='<%# DataBinder.Eval(Container, "DataItem.format") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.format") %>'>
                            <asp:ListItem id="liFormat0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFormat1" runat="server" Value="1">Print</asp:ListItem>
                            <asp:ListItem id="liFormat2" runat="server" Value="2">Reveal</asp:ListItem>
                            <asp:ListItem id="liFormat3" runat="server" Value="3">Both</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewFormatDDL" runat="server">
                            <asp:ListItem id="liFormat0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFormat1" runat="server" Value="1">Print</asp:ListItem>
                            <asp:ListItem id="liFormat2" runat="server" Value="2">Reveal</asp:ListItem>
                            <asp:ListItem id="liFormat3" runat="server" Value="3">Both</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
 
 
 
 
 
 
C#.NET Code Behind
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;
using System.DirectoryServices;
using System.Drawing;
 
namespace eForms
{
    public partial class updateReveal : System.Web.UI.Page
    {
        private SqlConnection myConnection;
        private int qsID;
        private string sqlSelect = "";
 
 
        public string GetUserName()
        {
            string retVal = string.Empty;
            string uname = User.Identity.Name.Split('\\')[1];
 
            DirectoryEntry userEntry = new DirectoryEntry("WinNT://domain/" + uname);
            retVal = (string)userEntry.Properties["fullname"].Value;
            return retVal;
        }
 
 
        protected void Page_Load(object sender, EventArgs e)
        {
            qsID = Int32.Parse(Request.QueryString["id"]);
 
            if (!Page.IsPostBack)
            {
                myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conForms"].ConnectionString);
                myConnection.Open();
 
                string sqlReveal = "select * from table where id = " + qsID;
 
                SqlCommand cmdReveal = new SqlCommand(sqlReveal, myConnection);
                SqlDataReader sdrReveal = cmdReveal.ExecuteReader(CommandBehavior.SingleRow);
 
                if (sdrReveal.Read())
                {
                    lblUser.Text = sdrReveal["newUser"].ToString();
                    lblRequestDate.Text = sdrReveal["requestDate"].ToString();
                    lblRequestor.Text = sdrReveal["requestedBy"].ToString();
                    lblName.Text = sdrReveal["newUser"].ToString();
                    lblID.Text = sdrReveal["newUserid"].ToString();
                    lblPositionLocation.Text = sdrReveal["positionLocation"].ToString();
                    lblSalesman.Text = sdrReveal["salesman"].ToString();
                    lblMirror.Text = sdrReveal["userMirror"].ToString();
                    lblApprovingSupervisor.Text = sdrReveal["approvingSupervisor"].ToString();
                }
                sdrReveal.Close();
 
 
                gvRevealDetails.DataSource = LoadData();
                gvRevealDetails.DataKeyNames = new string[] { "id" };
                gvRevealDetails.DataBind();
            }
        }
 
        protected DataTable LoadData()
        {
            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conForms"].ConnectionString);
            myConnection.Open();
 
            sqlSelect = "select id, rid, name, description, freq, db, format from table2 where rid = " + qsID;
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, myConnection);
 
            DataTable dt = new DataTable();
            //da.FillSchema(dt, SchemaType.Source);
            da.Fill(dt);
 	    dt.PrimaryKey = new DataColumn[] { dt.Column["id"] };	 
            Session["GridViewDataTable"] = dt;
            return dt;
 
        }
 
        private void UpdateDataSource(DataTable dt)
        {
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, myConnection);
            SqlCommandBuilder cb = new SqlCommandBuilder(da);
            da.Update(dt);
 
            Session["GridViewDataTable"] = dt;
        }
 
        private void BindDataGrid()
        {
            DataTable dt = ((DataTable)Session["GridViewDataTable"]);
 
            gvRevealDetails.DataSource = dt;
            gvRevealDetails.DataBind();
        }
 
        protected void gvRevealDetails_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
        {
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }
 
        protected void gvRevealDetails_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddNew"))
            {
                DataTable dt = (DataTable)Session["GridViewDataTable"];
 
                DataRow dr = dt.NewRow();
 
                dr["id"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewIDTextBox")).Text;
                dr["name"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportNameTextBox")).Text;
                dr["description"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportDescriptionTextBox")).Text;
                dr["freq"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFrequencyDDL")).Text;
                dr["db"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewDatabaseDDL")).Text;
                dr["format"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFormatDDL")).Text;
 
                dt.Rows.Add(dr);
                UpdateDataSource(dt);
 
                BindDataGrid();
            }
	else if (e.CommandName.Equals("Update"))
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
            LinkButton lnk = e.CommandSource as LinkButton;
            GridViewRow grow = lnk.NamingContainer as GridViewRow;
            DataRow row = dt.Rows.Find(int.Parse(lnk.CommandArgument));
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[grow.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[grow.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }
 
        }
 
        protected void gvRevealDetails_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
            int id = (int)gvRevealDetails.DataKeys[e.RowIndex].Value;
            dt.Rows.Find(id).Delete();
 
            UpdateDataSource(dt);
            BindDataGrid();
        }
 
        protected void gvRevealDetails_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
        {
            gvRevealDetails.EditIndex = e.NewEditIndex;
 
            BindDataGrid();
        }
 
       
    }
}

Open in new window

Author

Commented:
I thought I saw the ID in there before.  It is there.  I had taken the databinder's out of the .aspx file for the ID column a few minutes ago.  I just put them back, and the ID's are showing up.  Still the same error...

Author

Commented:
I'm trying your last post now.

Author

Commented:
I'm getting:

ExecuteReader: CommandText property has not been initialized

on row 393 in your post above.
Commented:
i made changes in apge load

.aspx:
 
 
<%@ Register TagPrefix="uc1" TagName="menu" Src="~/menu.ascx" %>
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="updateReveal.aspx.cs" Inherits="eForms.updateReveal" %>
 
<!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>Update Reveal Request</title>
    <link rel="stylesheet" type="text/css" href="../site.css" />
    <link rel="stylesheet" type="text/css" href="../print.css" />
</head>
<body>
    <form id="form1" method="post" runat="server">
    <uc1:menu ID="Menu" runat="server"></uc1:menu>
    <div id="content">
        <br />
        <div class="header1">
            Information Technology</div>
        <div class="header2">
            Pending ManMan / Reveal Reports Request for
            <asp:Label ID="lblUser" runat="server" />
        </div>
        <br />
        <br />
        <asp:Table ID="tblRevealInfo" runat="server" CellSpacing="2" Width="675" BorderWidth="0">
            <asp:TableRow>
                <asp:TableCell Width="400px">
                    Date of Request:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblRequestDate" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Requestor:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblRequestor" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Employee Name Needing Access:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblName" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Network ID of Employee Needing Access:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblID" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Position / Location:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblPositionLocation" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Salesman # (if applicable):
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblSalesman" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    User to Duplicate Access of
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblMirror" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow>
                <asp:TableCell>
                    Approving Supervisor:
                </asp:TableCell>
                <asp:TableCell>
                    <asp:Label ID="lblApprovingSupervisor" runat="server" />
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
        <br />
        <br />
        <asp:GridView ID="gvRevealDetails" runat="server" OnRowEditing="gvRevealDetails_RowEditing"
            OnRowCancelingEdit="gvRevealDetails_RowCancelingEdit" OnRowCommand="gvRevealDetails_RowCommand"
            OnRowDeleting="gvRevealDetails_RowDeleting"
            AutoGenerateColumns="false" Width="725px" ShowFooter="true">
            <Columns>
                <asp:TemplateField HeaderText="Edit" ShowHeader="false">
                    <EditItemTemplate>
                        <asp:LinkButton ID="lbUpdate" runat="server" Text="Update" CausesValidation="true"
                            CommandName="Update" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                        <asp:LinkButton ID="lbCancel" runat="server" Text="Cancel" CausesValidation="false"
                            CommandName="Cancel" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:LinkButton ID="lbEdit" runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" />
                    </ItemTemplate>
                    <FooterTemplate>
                        <asp:LinkButton ID="lbAdd" runat="server" CommandName="AddNew" Text="Add New" CausesValidation="false" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:CommandField HeaderText="Delete" ShowDeleteButton="true" ShowHeader="true" />
                <asp:TemplateField HeaderText="id" Visible="false">
                    <ItemTemplate>
                        <asp:Label ID="lblID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.id") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewIDTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="name">
                    <ItemTemplate>
                        <asp:Label ID="lblReportName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtReportName" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.name") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewReportNameTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="description">
                    <ItemTemplate>
                        <asp:Label ID="lblReportDescription" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.description") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtReportDescription" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.description") %>' />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="txtNewReportDescriptionTextBox" runat="server" />
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="freq">
                    <ItemTemplate>
                        <asp:Label ID="lblFrequency" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.freq") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlFrequency" runat="server" DataTextField='<%# DataBinder.Eval(Container, "DataItem.freq") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.freq") %>'>
                            <asp:ListItem id="liFreq0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFreq1" runat="server" Value="1">Daily</asp:ListItem>
                            <asp:ListItem id="liFreq2" runat="server" Value="2">Weekly</asp:ListItem>
                            <asp:ListItem id="liFreq3" runat="server" Value="3">Monthly</asp:ListItem>
                            <asp:ListItem id="liFreq4" runat="server" Value="4">Quarterly</asp:ListItem>
                            <asp:ListItem id="liFreq5" runat="server" Value="5">Annually</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewFrequencyDDL" runat="server">
                            <asp:ListItem id="liFreq0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFreq1" runat="server" Value="1">Daily</asp:ListItem>
                            <asp:ListItem id="liFreq2" runat="server" Value="2">Weekly</asp:ListItem>
                            <asp:ListItem id="liFreq3" runat="server" Value="3">Monthly</asp:ListItem>
                            <asp:ListItem id="liFreq4" runat="server" Value="4">Quarterly</asp:ListItem>
                            <asp:ListItem id="liFreq5" runat="server" Value="5">Annually</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="db">
                    <ItemTemplate>
                        <asp:Label ID="lblDatabase" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.db") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlDatabase" runat="server" DataTextField='<%# DataBinder.Eval(Container, "DataItem.db") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.db") %>'>
                            <asp:ListItem id="liDb0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liDb1" runat="server" Value="1">10-TMP</asp:ListItem>
                            <asp:ListItem id="liDb2" runat="server" Value="2">15-TMP LIFO</asp:ListItem>
                            <asp:ListItem id="liDb3" runat="server" Value="3">30-PPD</asp:ListItem>
                            <asp:ListItem id="liDb4" runat="server" Value="4">35-PPD LIFO</asp:ListItem>
                            <asp:ListItem id="liDb5" runat="server" Value="5">Inovice File</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewDatabaseDDL" runat="server">
                            <asp:ListItem id="liDb0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liDb1" runat="server" Value="1">10-TMP</asp:ListItem>
                            <asp:ListItem id="liDb2" runat="server" Value="2">15-TMP LIFO</asp:ListItem>
                            <asp:ListItem id="liDb3" runat="server" Value="3">30-PPD</asp:ListItem>
                            <asp:ListItem id="liDb4" runat="server" Value="4">35-PPD LIFO</asp:ListItem>
                            <asp:ListItem id="liDb5" runat="server" Value="5">Inovice File</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="format">
                    <ItemTemplate>
                        <asp:Label ID="lblFormat" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.format") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlFormat" runat="server" AppendDataBoundItems="true" DataTextField='<%# DataBinder.Eval(Container, "DataItem.format") %>'
                            DataValueField='<%# DataBinder.Eval(Container, "DataItem.format") %>'>
                            <asp:ListItem id="liFormat0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFormat1" runat="server" Value="1">Print</asp:ListItem>
                            <asp:ListItem id="liFormat2" runat="server" Value="2">Reveal</asp:ListItem>
                            <asp:ListItem id="liFormat3" runat="server" Value="3">Both</asp:ListItem>
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:DropDownList ID="ddlNewFormatDDL" runat="server">
                            <asp:ListItem id="liFormat0" runat="server" Value="0">Select</asp:ListItem>
                            <asp:ListItem id="liFormat1" runat="server" Value="1">Print</asp:ListItem>
                            <asp:ListItem id="liFormat2" runat="server" Value="2">Reveal</asp:ListItem>
                            <asp:ListItem id="liFormat3" runat="server" Value="3">Both</asp:ListItem>
                        </asp:DropDownList>
                    </FooterTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
    </form>
</body>
</html>
 
 
 
 
 
 
C#.NET Code Behind
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Net.Mail;
using System.DirectoryServices;
using System.Drawing;
 
namespace eForms
{
    public partial class updateReveal : System.Web.UI.Page
    {
        private SqlConnection myConnection;
        private int qsID;
        private string sqlSelect = "";
 
 
        public string GetUserName()
        {
            string retVal = string.Empty;
            string uname = User.Identity.Name.Split('\\')[1];
 
            DirectoryEntry userEntry = new DirectoryEntry("WinNT://domain/" + uname);
            retVal = (string)userEntry.Properties["fullname"].Value;
            return retVal;
        }
 
 
        protected void Page_Load(object sender, EventArgs e)
        {
            qsID = Int32.Parse(Request.QueryString["id"]);
             sqlSelect = "select id, rid, name, description, freq, db, format from table2 where rid = " + qsID;
            if (!Page.IsPostBack)
            {
                myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conForms"].ConnectionString);
                myConnection.Open();
 
                string sqlReveal = "select * from table where id = " + qsID;
 
                SqlCommand cmdReveal = new SqlCommand(sqlReveal, myConnection);
                SqlDataReader sdrReveal = cmdReveal.ExecuteReader(CommandBehavior.SingleRow);
 
                if (sdrReveal.Read())
                {
                    lblUser.Text = sdrReveal["newUser"].ToString();
                    lblRequestDate.Text = sdrReveal["requestDate"].ToString();
                    lblRequestor.Text = sdrReveal["requestedBy"].ToString();
                    lblName.Text = sdrReveal["newUser"].ToString();
                    lblID.Text = sdrReveal["newUserid"].ToString();
                    lblPositionLocation.Text = sdrReveal["positionLocation"].ToString();
                    lblSalesman.Text = sdrReveal["salesman"].ToString();
                    lblMirror.Text = sdrReveal["userMirror"].ToString();
                    lblApprovingSupervisor.Text = sdrReveal["approvingSupervisor"].ToString();
                }
                sdrReveal.Close();
 
 
                gvRevealDetails.DataSource = LoadData();
                gvRevealDetails.DataKeyNames = new string[] { "id" };
                gvRevealDetails.DataBind();
            }
        }
 
        protected DataTable LoadData()
        {
            myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["conForms"].ConnectionString);
            myConnection.Open();
 
            sqlSelect = "select id, rid, name, description, freq, db, format from table2 where rid = " + qsID;
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, myConnection);
 
            DataTable dt = new DataTable();
            //da.FillSchema(dt, SchemaType.Source);
            da.Fill(dt);
 	    dt.PrimaryKey = new DataColumn[] { dt.Column["id"] };	 
            Session["GridViewDataTable"] = dt;
            return dt;
 
        }
 
        private void UpdateDataSource(DataTable dt)
        {
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, myConnection);
            SqlCommandBuilder cb = new SqlCommandBuilder(da);
            da.Update(dt);
 
            Session["GridViewDataTable"] = dt;
        }
 
        private void BindDataGrid()
        {
            DataTable dt = ((DataTable)Session["GridViewDataTable"]);
 
            gvRevealDetails.DataSource = dt;
            gvRevealDetails.DataBind();
        }
 
        protected void gvRevealDetails_RowCancelingEdit(object sender, System.Web.UI.WebControls.GridViewCancelEditEventArgs e)
        {
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }
 
        protected void gvRevealDetails_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("AddNew"))
            {
                DataTable dt = (DataTable)Session["GridViewDataTable"];
 
                DataRow dr = dt.NewRow();
 
                dr["id"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewIDTextBox")).Text;
                dr["name"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportNameTextBox")).Text;
                dr["description"] =
                    ((TextBox)gvRevealDetails.FooterRow.FindControl("txtNewReportDescriptionTextBox")).Text;
                dr["freq"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFrequencyDDL")).Text;
                dr["db"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewDatabaseDDL")).Text;
                dr["format"] =
                    ((DropDownList)gvRevealDetails.FooterRow.FindControl("ddlNewFormatDDL")).Text;
 
                dt.Rows.Add(dr);
                UpdateDataSource(dt);
 
                BindDataGrid();
            }
	else if (e.CommandName.Equals("Update"))
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
            LinkButton lnk = e.CommandSource as LinkButton;
            GridViewRow grow = lnk.NamingContainer as GridViewRow;
            DataRow row = dt.Rows.Find(int.Parse(lnk.CommandArgument));
            row["name"] =
                ((TextBox)gvRevealDetails.Rows[grow.RowIndex].FindControl("txtReportName")).Text;
            row["description"] =
                ((TextBox)gvRevealDetails.Rows[grow.RowIndex].FindControl("txtReportDescription")).Text;
            row["freq"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlFrequency")).Text;
            row["db"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlDatabase")).Text;
            row["format"] =
                ((DropDownList)gvRevealDetails.Rows[grow.RowIndex].FindControl("ddlFormat")).Text;
 
            UpdateDataSource(dt);
 
            gvRevealDetails.EditIndex = -1;
 
            BindDataGrid();
        }
 
        }
 
        protected void gvRevealDetails_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
        {
            DataTable dt = (DataTable)Session["GridViewDataTable"];
 
            int id = (int)gvRevealDetails.DataKeys[e.RowIndex].Value;
            dt.Rows.Find(id).Delete();
 
            UpdateDataSource(dt);
            BindDataGrid();
        }
 
        protected void gvRevealDetails_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
        {
            gvRevealDetails.EditIndex = e.NewEditIndex;
 
            BindDataGrid();
        }
 
       
    }
}

Open in new window

Author

Commented:
Closer, but it looks like we're going to have to put the rowupdating event back in.  Here's what happened...

The GridView 'gvRevealDetails' fired event RowUpdating which wasn't handled.

Author

Commented:
PARTIAL SUCCESS!!!  I just tested the Add New and Delete functionality.  For the first time EVER, both are working!!!!  The Add New isn't autoincrementing the int identity in the database which I'll have to figure out, but i fyou type in a value it works!  It'll be 100% complete if we can just get the edit working!!

Author

Commented:
WE GOT IT!!!!!!!!!!  I added the rowupdating back into the .aspx and the code behind and commented out the updating lines of code in the row command and got it all working!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

I CAN'T POSSIBLY THANK YOU ENOUGH!!!!!!!!  THANK YOU THANK YOU THANK YOU THANK YOU!!!!!!!!!!!!!

Author

Commented:
This was a HUGE!!!!!!!!! half-day effort jinal spent helping me on this.  You'll have to read the entire post to stand a chance at getting all of the information out of it to get a similar solution to work.  jinal deserves thousands of points for this answer!!!  Thank you so much!!!!!!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial