如何从ASP.NET中的DetailsView控件获取价值? [英] How to get value from DetailsView Control in ASP.NET?
问题描述
我的页面上有DetailsView.我设置了 DefaultMode ="Edit"
.现在,我想获取用户将在此单元格中编辑的值.
I have DetailsView on my page. I set DefaultMode="Edit"
. Now i want to get value that user will edit in this cell.
<asp:DetailsView ID="dvApplicantDetails" runat="server"
AutoGenerateRows="false" DataKeyNames="ApplicantID" DefaultMode="Edit"
onitemcommand="dvApplicantDetails_ItemCommand" >
<Fields>
<asp:BoundField DataField="ApplicantID" HeaderText="ApplicantID" ReadOnly="true"/>
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:CommandField ButtonType="Button" ShowEditButton="true" EditText="Update" ShowCancelButton="false" />
</Fields>
</asp:DetailsView>
我尝试了多种方法来获得此值,例如:
I've tried many ways to get this value, such as:
protected void dvApplicantDetails_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
string firstName = dvApplicantDetails.Rows[1].Cells[1].Text;
string lastName = dvApplicantDetails.Rows[2].Cells[1].Text;
}
}
但是它不起作用...如何使用此模式获取此值.我知道我可以使用< ItemTemplate>
而不是< BoundField>
,但是无论如何,这应该是从此字段中获取此值的某种方法.请帮助!谢谢!
But it doesn't work... How to get this value using this mode. I know that i can use <ItemTemplate>
instead of <BoundField>
, but anyway it should be some way to get this value from this field.
Help please!
Thank you!
推荐答案
不幸的是,尝试访问 .. Cells [1]
的 Text
寻找.您需要该单元格中 TextBox
控件的值:
Unfortunately, trying to access the Text
of ..Cells[1]
is not what you are looking for. You need the value of the TextBox
control within that cell:
protected void dvApplicantDetails_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
string firstName = ((TextBox)dvApplicantDetails.Rows[1].Cells[1].Controls[0]).Text;
string lastName = ((TextBox)dvApplicantDetails.Rows[2].Cells[1].Controls[0]).Text
}
}
这篇关于如何从ASP.NET中的DetailsView控件获取价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!