在gridview之外的事件上获取TextBox值(动态设置) [英] Getting TextBox Value(Set Dynamically) on an event outside gridview

查看:59
本文介绍了在gridview之外的事件上获取TextBox值(动态设置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在gridview中有一个文本框.我将在运行时设置文本框的文本.

现在,我想在gridview外部的按钮单击事件时访问文本框的文本.

HTML:

Hi,

I have a textbox inside a gridview. I will set the text of the textbox in runtime.

Now I want to access the text of the textbox on click event of a button outside gridview.

HTML:

 <asp:GridView runat="server" Id="grdRuleFieldMapping" AutoGenerateColumns="false">
<columns>
<asp:BoundField HeaderText="Field Mapping" DataField="FiledMapping">
<asp:TemplateField HeaderText="Mapping Text">                     <itemtemplate><asp:TextBox runat="server" ID="txtMappingText"></itemtemplate><asp:TemplateField><columns>
        
        <asp:Button runat="server" ID="btnSubmit" Text="Submit" OnClick="btnSubmit_Click"></columns></columns>



后台代码:



Code-Behind:

protected void btnSubmit_Click(object sender, EventArgs e)
       {
           foreach (GridViewRow grdRow in grdRuleFieldMapping.Rows)
           {
               TextBox objTxt1 = (TextBox)grdRow.Cells[1].FindControl("txtMappingText");
           }
       }

推荐答案

这是查找文本框时的正确方法.

我没有发现任何错误.如果找到任何内容,则可以在此处声明.

但是,让我告诉您一些有关扩展代码以获取文本框值的信息

That''s right way as you''re finding textbox.

I am not finding any Error of something wrong in it. If you''re finding any then you can state it here.

But Let me tell you about some expansion to your code for getting textbox value

protected void btnSubmit_Click(object sender, EventArgs e)
       {
           foreach (GridViewRow grdRow in grdRuleFieldMapping.Rows)
           {
               TextBox objTxt1 = (TextBox)grdRow.Cells[1].FindControl("txtMappingText");
//Check if TextBox is not null
if(objTxt1 != null)
{
string reqText = objTet1.Text;
}
           }
       }



希望您正在寻找相同的东西.



Hope you were searching for the same thing.


亲爱的朋友,

文本框应位于
Dear Friend ,

The text box should inside the
<br />
<asp:TemplateField HeaderText="Mapping Text"><br />
<Itemtemplate><br />
<asp:textbox runat="server" id="txtMappingText" > <br />
<br />
<br />
</Itemtemplate><br />


但对不起,您缺少将数据绑定到文本框的消息,对吗?
您应该以任何方式绑定文本数据以在Text属性中访问它们


but sorry are you missing binding data to the Textbox , aren''t you ?
any way you should bind text data to access them in the Text attribute

<br />
<asp:textbox runat="server" id="txtMappingText" text="<%# Eval("Feild Name")%>" ><br />



如果您想设置数据,只需在
获得objTxt1时进行设置



and if you want to set data you just set it when you get the objTxt1 by

<br />
objTxt1.Text="Your Value";<br />



问候
Ab Abulubbad



regards
Ab Abulubbad


啊哈,现在我明白了,如果您将databidbid函数放入Page_Load()

aha now i got it , look you should put your databiding function if its inside the Page_Load()
inside
<br />
if(!IsPostBack)<br />
{<br />
//BidingFunction<br />
}<br />



您没有得到用户重视,因为您在页面回发时再次绑定了数据.

AB Abulubbad



your not getting the user valuse because you binding data again when the page is posted back .

AB Abulubbad


这篇关于在gridview之外的事件上获取TextBox值(动态设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆