Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts,

I have a Gridview with few bound fields. Also has a link button which opens a modal popup of clicked row to edit/add same row. Here is what I tried.
VB
Dim lnk As LinkButton = TryCast(sender, LinkButton)
            Dim gr As GridViewRow = DirectCast(lnk.NamingContainer, GridViewRow)
            Dim tempID As Integer = Convert.ToInt32(gr.RowIndex)

            For i As Integer = 1 To gdvLineItems.Rows.Count - 1
                Dim row = gdvLineItems.Rows(i)

                Dim rowHeaderCell = row.Cells(0)
                Dim tempval = row.FindControl("lblRowNumber")

                If tempID = DirectCast(tempval, System.Web.UI.WebControls.Label).Text.ToString().Trim() Then
                    '  If tempID = rowHeaderCell.Text.ToString().Trim() Then
                    txtMDOT.Text = row.Cells(1).Text.ToString().Trim()
                    txtM32nds.Text = row.Cells(3).Text.ToString().Trim()
                    txtMApprNbr.Text = row.Cells(7).Text.ToString().Trim()
                    txtMPosition.Text = row.Cells(4).Text.ToString().Trim()
                    txtMProdCode.Text = row.Cells(6).Text.ToString().Trim()
                    txtMRR.Text = row.Cells(8).Text.ToString().Trim()
                    ddlMRemAre.SelectedValue = row.Cells(5).Text.ToString().Trim()
                    txtMSize.Text = row.Cells(2).Text.ToString().Trim()
                End If
Next
mpCopyRow.Show()


Everything seems working ok except a minor issue.

Suppose My Gridview has 3 rows
1 apple - - - - - -
2 Banana - - - - - -
3 Orange - - - - - -

Now if I click on Banana, I get Banana's details
But if I click on apple, I don't get any.
Meaning every time user clicks on first row of gridview it doesn't show any.
Can anyone help me with this please?
Posted

rather than this
For i As Integer = 1 To gdvLineItems.Rows.Count - 1

next
you can try with
For i As Integer = 0 To gdvLineItems.Rows.Count - 1

next
 
Share this answer
 
Comments
sudevsu 27-May-15 9:12am    
Thank you
As I am seeing your code you have started
For i As Integer = 1 To gdvLineItems.Rows.Count - 1

But it should be
For i As Integer = 0 To gdvLineItems.Rows.Count - 1

because rowindex always starts from 0.
 
Share this answer
 
Comments
sudevsu 27-May-15 9:13am    
Thank you. Same answer as solution 1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900