开发者

Access Textbox content that is inside a detailsView cell

开发者 https://www.devze.com 2023-03-22 22:58 出处:网络
Hi I need to access the contents of a textbox that is inside a details view: <asp:TemplateField HeaderText=\"Transaction Name:\" >

Hi I need to access the contents of a textbox that is inside a details view:

<asp:TemplateField HeaderText="Transaction Name:" > 
                <InsertItemTemplate>
                    <asp:TextBox ID="txtTransactionName" runat="server" />
                </InsertItemTemplate>            
</asp:TemplateField>

Tried string v = ((TextBox)detailsNew.FindControl("txtTran开发者_运维百科sactionName")).Text; but it returned "" when I checked. EDIT: I'm trying the above in detailsNew_ItemInserting(...)


You could try like...

protected void detailsNew_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
  string v = ((TextBox)((DetailsView)sender).FindControl("txtTransactionName")).Text;
}


First this Item template control have to be binded with a property from your data source so that when the item inserting event is fire you can access it's data using this code

e.Values["ColumnName"]


Found the problem. Leaving this here to help someone else who might have the same problem.

I cannot use the sender object to get the DetailsView. So the correct way:

TextBox txt = (TextBox)DETAILSVIEW_ID.FindControl("TEXTBOX_ID") as TextBox;
string tmp = txt.Text;

DETAILSVIEW_IDis the ID of the DetailsView and TEXTBOX_ID the ID of the TextBox crated inside the DetailsView.

0

精彩评论

暂无评论...
验证码 换一张
取 消