问题描述
大家好!我正在使用Visual Studio 2008,但无法从gridview的控件中提取数据.这就是它的工作方式:用户单击编辑"按钮,所选行将变为文本框和下拉列表供他们选择.编辑后,他们单击更新,它将被更新.但是,当我单击更新时,rowupdating方法将连续执行两次,并且数据检索将是原始数据,而不是已编辑的数据.例如,如果文本框中的数据为A,而我将其更改为B,则当我单击更新时,它将采用A数据.而对于dropdownlist,它将读取第一个列表项.
下面是代码:
Hi all! I''m using visual studio 2008 and i''m having trouble extracting the data out from the controls in the gridview. This is how it''s supposed to work: user clicks on edit button, the selected row would change to textboxes and dropdownlist for them to choose. Once edited, they click on update and it will be updated. However, when i click on update, the rowupdating method is executed twice in a row and the data retrieve would be the original data instead of the edited ones. For example, if the data in the textbox is A and i change it to B, when i click on update, it would take the A data. Whereas for dropdownlist, it would read the 1st list item.
Below is the code:
<EditItemTemplate>
<asp:TextBox ID="txtDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "date") %>'></asp:TextBox>
</EditItemTemplate>
这是在rowupdating方法中执行的:
This is executed in the rowupdating method:
Dim ddlduty As DropDownList
Dim txtDate As TextBox
Dim txtHrs As TextBox
Dim duty As String
Dim dutyDate As Date
Dim hrs As Integer
Dim row As GridViewRow = gvTimesheet.Rows(e.RowIndex)
ddlduty = CType(row.FindControl("ddlDuties"), DropDownList)
txtDate = CType(row.FindControl("txtDate"), TextBox)
txtHrs = CType(row.FindControl("txtHrs"), TextBox)
duty = ddlduty.SelectedValue
dutyDate = CType(txtDate.Text, Date)
hrs = CType(txtHrs.Text, Integer)
推荐答案
这篇关于无法从gridview中的控件检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!