如何在asp.net中的gridview中放置文本框值 [英] how to get text box value placed in gridview in asp.net
本文介绍了如何在asp.net中的gridview中放置文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用了
GridViewRow row =(GridViewRow)(((LinkButton)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 $ c中给出$ c> in
GridView
,
< asp:GridView ID = gvScripts runat = server AutoGenerateColumns = False OnRowCommand = gvScripts_RowCommand DataKeyNames = DL_RECID >
< 列 >
< asp:TemplateField HeaderText = HeaderStyle-HorizontalAlign = center HeaderStyle-Width = 30px >
< ItemStyle CssClass = HRLineCDL Wrap = true HorizontalAlign = 中心 > < / 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
解决方案
InGridview
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 withImageButton
. So, when I click this button, I need to get the value of a column (ofSelectedRow
), which is given inDataKeyNames
inGridView
,
<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屋!
查看全文