Solved

Update Datagrid w/ template column and dataview

Posted on 2004-08-09
3
332 Views
Last Modified: 2008-02-01
Hi Experts!,

I am having a problem with the udpate command of my datagrid which has both a template column and a dataview applied.  The code works fine without the dataview, but something about the dataview messes up the update command and only on the column containing the template column.
The only column with a edit item template is column #4

****************************UPDATE COMMAND***********************************************

 Private Sub dgTaskEdit_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgTaskEdit.UpdateCommand
        Dim dv As DataView = DsTaskEdit1.Tables(0).DefaultView
        dv.RowFilter = " Owner ='" + LastName + "'"
        Dim SelRow As System.Data.DataRowView    
        SelRow = dv.Item(e.Item.ItemIndex)

        Dim udProjectName As TextBox = e.Item.Cells(3).Controls(0)
        'Dim udDescription As TextBox = e.Item.Cells(4).Controls(0) 'old line that worked before converted to template column
        Dim udDescription As TextBox = CType(e.Item.Cells(4).FindControl("txtDescriptionUser"), TextBox) 'line that bombs!

        Dim udOwner As TextBox = e.Item.Cells(5).Controls(0)
        Dim udRequestor As TextBox = e.Item.Cells(6).Controls(0)
        Dim udDueDate As TextBox = e.Item.Cells(7).Controls(0)

        Dim sqlstr As String
        sqlstr = "UPDATE tasks SET ProjectName = '" + udProjectName.Text + "', Description = '" + udDescription.Text + "', Owner = '" + udOwner.Text + "', requestor = '" + udRequestor.Text + "', DueDate = '" + udDueDate.Text + "'  WHERE taskID = " + SelRow("taskID").ToString()
        'SQLCommandText = "INSERT into tasks (ProjectName, DateEntered, Owner, Requestor, Description, DueDate) Values ('" + ddlProject.SelectedItem.ToString() + "','" + Date.Now.ToString() + "', '" + ddlOwner.SelectedItem.ToString() + "', '" + ddlRequestor.SelectedItem.ToString() + "', '" + txtTaskDescription.Text + "', '" + DateTime.Parse(ddlMonth.SelectedItem.ToString() + "/" + ddlDay.SelectedItem.ToString() + "/" + ddlYear.SelectedItem.ToString()) + "') "


        Dim sqlCommand As New SqlClient.SqlCommand()
        sqlCommand.CommandText = sqlstr
        sqlCommand.Connection = conTasks
        conTasks.Open()
        sqlCommand.ExecuteNonQuery()
        conTasks.Close()
        DsTaskEdit1.Reset()
       
        daTasks.Fill(DsTaskEdit1)
        dgTaskEdit.DataBind()
        dgTaskEdit.EditItemIndex = -1
        Server.Transfer("EditTaskUser.aspx")
    End Sub

***************************************************************************************

<asp:TemplateColumn SortExpression="description" HeaderText="Description">
      <ItemTemplate>
<asp:Label id=Label1 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Description") %>'></asp:Label>
      </ItemTemplate>
      <EditItemTemplate>
      <asp:TextBox id=txtDescriptionUser runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Description") %>' TextMode="MultiLine">
                                          </asp:TextBox>
      </EditItemTemplate>
</asp:TemplateColumn>
0
Comment
Question by:jcraun
[X]
Welcome to Experts Exchange

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

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
Daniellus83 earned 500 total points
ID: 11757941
Try insert the folowing code (behind the code runat="server" in the asp templeteColumn )

OnPageIndexChanged="pager"


and use this vb.net code to active some code when something is changed/set on yout Datagrid:

    Sub pager(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
         'Your update code
    End Sub
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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