[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Update Datagrid w/ template column and dataview

Posted on 2004-08-09
3
Medium Priority
?
355 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
1 Comment
 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

829 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