且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取Datagrid模板控件值时出现问题

更新时间:2022-05-15 02:40:31

我从没做过,但是您能为文本框添加一个EventHandler吗?
I have never done that, but could you just add an EventHandler for the Textbox?
<asp:TextBox runat="server" OnTextChanged="Text_OnTextChanged" ID="Text"></asp:TextBox>



在CodeBehind中,您可以仅使用发送方来获取文本:



In the CodeBehind you can just use the sender to get the Text:

protected void TextBox1_TextChanged(object sender, EventArgs e)
{
  TextBox text = sender as TextBox;
  text.Text; //this is the text.
}


虽然这看起来像实际的代码,但这是未经测试的伪代码,仅供说明!

在您澄清后添加:
好的,所以您需要这样做:


While this might look like actual Code, this is untested pseudocode for illustration only!

Added after your clarification:
Ok so you need this:

Sub GridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs){
	Dim index As Integer = Convert.ToInt32(e.CommandArgument)
	Dim row As GridViewRow = GridView.Rows(index)
	TextBox lName = row.FindControl("Lname") as TextBox;
	TextBox fName = row.FindControl("FName") as TextBox;
	Label empId = row.FindControl("EmpId") as Label;
}



假设您所有的控件都在ASP标记id="Lname"中设置了这样的ID.这需要与FindControl的参数完全相同.

希望这会有所帮助,并且不要再有经过检查的代码可能包含错字.



Assuming all your Controls have the id set like this in the ASP Markup id="Lname". This needs to be exactly like the Parameter of FindControl.

Hope this helps, and again no checked code, may contain typos.