获取Datagrid模板控件值时出现问题 [英] Problem in getting Datagrid template control value
问题描述
大家好,
我正在使用asp.net 4.0
我有数据网格,并放置了一些模板字段(文本框).
我想在textbox_textchange事件上获取这些文本框的值,但我无法.
请任何人都可以帮助我,我会发自内心的感激.
Raj
Hi All,
I am using asp.net 4.0
I have Data grid and i have put some template fields (textboxes).
I want to get the values of these text boxes on textbox_textchange event but i am unable.
Please any one can help me i will appreciate from my core of heart.
Raj
推荐答案
我从没做过,但是您能为文本框添加一个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.
这篇关于获取Datagrid模板控件值时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!