Solved

Update Datagrid w/ template column and dataview

Posted on 2004-08-09
3
313 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

20 Experts available now in Live!

Get 1:1 Help Now