[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Update Datagrid w/ template column and dataview

Posted on 2004-08-09
3
Medium Priority
?
352 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 2000 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

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…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 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