Gridview rowindex和绑定值的问题 [英] Issues with Gridview rowindex and bind value
问题描述
Hello Experts,
我有一个Gridview,只有很少的绑定字段。还有一个链接按钮,用于打开单击行的模式弹出窗口以编辑/添加同一行。这是我试过的。
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.
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()
除了一个小问题,一切似乎都正常。
假设我的Gridview有3行
1苹果 - - - - - -
2香蕉 - - - - - -
3橙色 - - - - - -
现在,如果我点击Banana,我会收到Banana的详细信息>
但是如果我点击苹果,我就不会得到任何。
意思是每当用户点击gridview的第一行时,它就不会 显示任何。
有谁可以帮我这个吗?
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?
推荐答案
而不是这个
我的整数= 1 to gdvLineItems.Rows.Count - 1
next
你可以试试
For i As Integer = 0到gdvLineItems.Rows.Count - 1
next
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
当我看到你的代码时,你已经开始了
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
因为rowindex总是从0开始。
because rowindex always starts from 0.
这篇关于Gridview rowindex和绑定值的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!