如何在asp.net中的gridview中放置文本框值 [英] how to get text box value placed in gridview in asp.net

查看:123
本文介绍了如何在asp.net中的gridview中放置文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用了



 GridViewRow row =(GridViewRow)(((LinkBut​​ton)e.CommandSource).NamingContainer); 
TextBox txtcmt =(TextBox)row.FindControl(txtComment);

string c = txtcmt.text





txtcmt 返回 null value

plz help ....

谢谢

解决方案

Gridview RowCommand

 受保护  void  gvScripts_RowCommand( object  sender,GridViewCommandEventArgs e)
{
if (e.CommandName == IFullView
{
int index = 0 ;
string lstrVal = ;

if (e.CommandArgument!=
{
index = Convert.ToInt32(e.CommandArgument);
lstrVal = gvScripts.DataKeys [index] .Value.ToString()。Trim();
}
}
}



并且在。 aspx



我有一个 ImageButton 的列。因此,当我单击此按钮时,我需要获取一列( SelectedRow )的值,该值在 DataKeyNames in GridView

 <   asp:GridView     ID   =  gvScripts    runat   =  server    AutoGenerateColumns   =  False    OnRowCommand   =  gvScripts_RowCommand    DataKeyNames   =  DL_RECID  >  

< >
< asp:TemplateField HeaderText = HeaderStyle-Horizo​​ntalAlign = center HeaderStyle-Width = 30px >
< ItemStyle CssClass = HRLineCDL Wrap = true Horizo​​ntalAlign = 中心 > < / ItemStyle > ;
< ItemTemplate >
< asp:ImageButton ID = btnIFullView < span class =code-attribute> AlternateText = 完整视图 runat = server CommandName = IFullView

CommandArgument = <%#((GridViewRow)容器).RowIndex%> / >
< / ItemTemplate >

< / asp:TemplateField >
< /列 >


查看 CodeProject常见问题系列1:ASP.NET GridView [ ^ ]。


你好,



请参考 - 如何使用gridview控件的值填充文本框? [ ^ ]



它可能对你有所帮助/>






添加链接文字以反映文章标题。

[/编辑]

I used

GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
 TextBox txtcmt = (TextBox)row.FindControl("txtComment");

string c=txtcmt.text



but txtcmt returns null value
plz help....
Thanks

解决方案

In Gridview RowCommand,

protected void gvScripts_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "IFullView")
    {
        int index = 0;
        string lstrVal = "";

        if (e.CommandArgument != "")
        {
            index = Convert.ToInt32(e.CommandArgument);
            lstrVal = gvScripts.DataKeys[index].Value.ToString().Trim();
        }
    }
}


And in .aspx,

I have a column with ImageButton. So, when I click this button, I need to get the value of a column (of SelectedRow), which is given in DataKeyNames in GridView,

<asp:GridView ID="gvScripts" runat="server" AutoGenerateColumns="False" OnRowCommand="gvScripts_RowCommand" DataKeyNames="DL_RECID">

    <Columns>
        <asp:TemplateField HeaderText="" HeaderStyle-HorizontalAlign="center" HeaderStyle-Width="30px">
            <ItemStyle CssClass="HRLineCDL" Wrap="true" HorizontalAlign="Center"></ItemStyle>
            <ItemTemplate>
                <asp:ImageButton ID="btnIFullView" AlternateText="Full View" runat="server" CommandName="IFullView"

                    CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
            </ItemTemplate>
    
        </asp:TemplateField>
    </Columns>


Check out CodeProject Frequently Asked Questions Series 1: The ASP.NET GridView[^].


Hello,

Please refer - How to populate textbox with value of gridview control?[^]

It may be helpful for you.


[Edit member="Tadit"]
Link text added to reflect the article title.
[/Edit]


这篇关于如何在asp.net中的gridview中放置文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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