在我的gridview中,一些行已经存在。 Gridview有一列包含链接按钮。但是,当我在gridview中添加新行时,我只想为该新行更改该链接按钮的文本。如何在运行时在asp.net中更改gridview中的链接按钮文本
在此先感谢。
在我的gridview中,一些行已经存在。 Gridview有一列包含链接按钮。但是,当我在gridview中添加新行时,我只想为该新行更改该链接按钮的文本。如何在运行时在asp.net中更改gridview中的链接按钮文本
在此先感谢。
看看你的gridview事件,你可以访问事件处理程序中的特定行属性。
例如,RowCreated: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcreated.aspx
GridView控件不支持插入新行像我们更新/删除row.This意味着有用于插入行没有这样的内建功能的方式。显然这个问题有解决方法。您可能会说有GridView的RowCreated
事件,但是,当GridView呈现自身并且与RowDataBound
密切相关时,会引发此事件。
获取手动插入新行的最简单方法是使用DetailsView。
DetailsView:
添加一个CommandField里面详细的<Fields>
段查看如下:
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
AutoGenerateRows="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"/>
<asp:BoundField DataField="ContactName" HeaderText="ContactName"/>
<asp:CommandField ShowDeleteButton="False" ShowEditButton="True"
ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
你还需要有如下一个SqlDataSource
控制:
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName]) VALUES (@CustomerID, @CompanyName, @ContactName)" >
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="CompanyName" Type="String" />
<asp:Parameter Name="ContactName" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
但是,如果你还在NT使用的网格视图只使用一些解决方法,下面的链接值得一看: http://aspsnippets.com/Articles/Adding-Dynamic-Rows-in-ASP.Net-GridView-Control-with-TextBoxes.aspx
到这个链接 这将帮助您与您需要的控件动态添加行
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html