Solved

Update Datagrid w/ template column and dataview

Posted on 2004-08-09
3
326 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
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

792 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