Advertisement

12.15.2003 at 11:50AM PST, ID: 20826376
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

asp.net - DataGrid:  Highlight a selected row

Asked by jay-are in .NET

Tags: , ,

Hello Experts:

I'm trying to highlight a row inside a editable datagrid.  When the user clicks "edit" I'd like to highlight that row until they click "update" or "cancel".  I'll include my code below.  I'm looking for a solution in VB.Net.  I find a lot of solutions online that are for C#.

Thanks for your help!

Here are my subs for editing and updating:

Edit:

Sub DataGrid_Edit(Sender As Object, E As DataGridCommandEventArgs)
   
                        ' turn on editing for the selected row
   
                       
                Dim CommentBox As Textbox
                          DataGrid1.EditItemIndex = e.Item.ItemIndex
                          Dim scriptJs As String
                                    
      BindGrid()
                              
      CommentBox = CType(DataGrid1.Items(DataGrid1.EditItemIndex).Cells(7).Controls(0), TextBox)
      scriptJs = "<script language=javascript>" & vbCrLf
      scriptJs &= "document.getElementById('" & CommentBox.UniqueID & "').focus();" & vbCrLf
      scriptJs &= "document.getElementById('" & CommentBox.UniqueID & "').select();" & vbCrLf
      scriptJs &= "<" & "/script>"
      If (Not Me.IsStartupScriptRegistered("Startup")) Then
      Me.RegisterStartupScript("Startup", scriptJs)
      End If
                              
        End Sub

Update:
               Sub DataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)
   
                        ' update the database with the new values
   
                        ' get the edit text boxes
                        Dim Control As String = CType(e.Item.Cells(0).Controls(0), textbox).Text
                        Dim CommentBox As String = CType(e.Item.Cells(7).Controls(0), textbox).Text
   
                        ' TODO: update the Command value for your application
                        Dim myConnection As New SqlConnection(ConnectionString)
                        Dim UpdateCommand As SqlCommand = new SqlCommand()
                        UpdateCommand.Connection = myConnection
   
                        If AddingNew = True Then
                            UpdateCommand.CommandText = "INSERT INTO comments1130(ControlNo, CommentBox) VALUES (@Contno, @CommentBox)"
                        Else
                            UpdateCommand.CommandText = "UPDATE comments1130 SET CommentBox = @CommentBox WHERE controlNo = @ContNo"
                        End If
                        UpdateCommand.Parameters.Add("@ContNo", SqlDbType.VarChar, 8000).Value = Control
                        UpdateCommand.Parameters.Add("@CommentBox", SqlDbType.VarChar, 99).Value = CommentBox
   
                        ' execute the command
                        Try
                            myConnection.Open()
                            UpdateCommand.ExecuteNonQuery()
   
                        Catch ex as Exception
                            Message.Text = ex.ToString()
   
                        Finally
                            myConnection.Close()
   
                        End Try
   
                        ' Resort the grid for new records
                        If AddingNew = True Then
                            DataGrid1.CurrentPageIndex = 0
                            AddingNew = false
                        End If
   
                        ' rebind the grid
                        DataGrid1.EditItemIndex = -1
                        BindGrid()
               End Sub

And finally the datagrid:

asp:datagrid id="DataGrid1" runat="server" enableviewstate="true" ShowFooter="true" OnItemDataBound="ComputeSum" Font-Size="10pt" AutoGenerateColumns="False" width="90%" CellSpacing="2" GridLines="None" HorizontalAlign="Center" CellPadding="3" BackColor="White" ForeColor="Black" OnPageIndexChanged="DataGrid_Page" PageSize="12" AllowPaging="true" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" OnEditCommand="DataGrid_Edit" OnItemCommand="DataGrid_ItemCommand" DataKeyField="Control#">
            <HeaderStyle font-bold="True" forecolor="white" backcolor="#4A3C8C"></HeaderStyle>
            <PagerStyle horizontalalign="Right" backcolor="#C6C3C6" mode="NumericPages" font-size="smaller"></PagerStyle>
            <ItemStyle backcolor="#DEDFDE"></ItemStyle>
            <FooterStyle backcolor="#C6C3C6"></FooterStyle>
            <Columns>
                <asp:BoundColumn DataField="Control#" ReadOnly="False" HeaderText="Cust. Number" />
                <asp:BoundColumn DataField="Reference#" ReadOnly="True" HeaderText="Reference#" />
                <asp:BoundColumn DataField="Document Date" DataFormatString="{0:d}" ReadOnly="True" HeaderText="Document Date" />
                <asp:BoundColumn DataField="Last Name" ReadOnly="True" HeaderText="Last Name" />
                <asp:boundColumn DataField="First Name" ReadOnly="True" HeaderText="First Name" />
                <asp:BoundColumn DataField="SumAmt" DataFormatString="{0:c}" ReadOnly="True" HeaderText="Amount" />
                <asp:BoundColumn DataField="daysold" ReadOnly="True" HeaderText="Days Old" />
                <asp:BoundColumn DataField="CommentBox" HeaderText="Comments" ReadOnly="False" />
                        <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" ItemStyle-Font-Size="smaller" ItemStyle-Width="7%" onclick="javascript:HighlightRow(this);"></asp:EditCommandColumn>
                        
            </Columns>
        </asp:datagrid>
Start Free Trial
[+][-]12.15.2003 at 12:09PM PST, ID: 9944393

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.15.2003 at 12:12PM PST, ID: 9944414

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.15.2003 at 02:02PM PST, ID: 9945278

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.15.2003 at 09:10PM PST, ID: 9947179

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: .NET
Tags: datagrid, row, selected
Sign Up Now!
Solution Provided By: x_com
Participating Experts: 6
Solution Grade: A
 
 
[+][-]12.16.2003 at 06:59AM PST, ID: 9949585

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.16.2003 at 06:23PM PST, ID: 9954071

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2004 at 06:06AM PDT, ID: 11415213

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.28.2004 at 09:54AM PDT, ID: 11417524

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.26.2004 at 01:25AM PDT, ID: 11900544

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.26.2004 at 02:15PM PDT, ID: 11907614

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.16.2004 at 08:12AM PDT, ID: 12075542

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.16.2004 at 10:18AM PDT, ID: 12077008

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2004 at 12:24AM PDT, ID: 12082040

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-38