[英]clicking on link button in gridview does not show the details in detailsview
I have a grid view and a details view. 我有一个网格视图和一个详细信息视图。 In that grid view I have a link button column in the first column. 在该网格视图中,我在第一列中有一个链接按钮列。 When I click on the link button column it has to show the corresponding row values in the details view. 当我单击链接按钮列时,它必须在详细信息视图中显示相应的行值。 I am using separate data sources for details view and grid view. 我将单独的数据源用于详细信息视图和网格视图。
This is the grid view code: 这是网格视图代码:
<asp:GridView ID="GridView2" runat="server"
DataSourceID="SqlDataSourcegridview" Height="533px" Width="316px"
style="text-align: left" EnableCallBack="false"
AutoGenerateColumns="False" >
<Columns>
<asp:TemplateField ShowHeader="false">
<HeaderTemplate>
<asp:Label ID="lbl1" runat="server" Text="DCN"></asp:Label>
</HeaderTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkname" runat="server" SortExpression="DCN"
Text='<%#Eval("DCN") %>' CausesValidation="false"
CommandName='<%#Eval("DCN")%>' OnClick = "Link_buttonClick">
linkbutton
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="priority" HeaderText="priority"
SortExpression="priority" />
</Columns>
</asp:GridView>
Datasource for gridview: gridview的数据源:
<asp:SqlDataSource ID="SqlDataSourcegridview" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectDBString %>"
SelectCommand="SELECT * FROM [MASTERETMTABLE] WHERE ([DCN] = @DCN)">
<SelectParameters>
<asp:Parameter DefaultValue="BAT" Name="DCN" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Details view: 详细信息视图:
<asp:Panel ID="paneldetails" runat="server" BackColor="#CCCCCC"
Visible="False" >
<asp:DetailsView ID="detailsvw" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSourcedetailsview" Width="424px">
<Fields>
<asp:BoundField DataField="DCN" HeaderText="DCN" SortExpression="DCN" />
<asp:BoundField DataField="PRIORITY" HeaderText="PRIORITY"
SortExpression="PRIORITY" />
</Fields
</asp:DetailsView>
</asp:Panel>
and this is my datasource for details view 这是我的详细信息视图的数据源
<asp:SqlDataSource ID="SqlDataSourcedetailsview" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectDBString %>"
SelectCommand="SELECT * FROM [MASTERETMTABLE] WHERE ([DCN] = @DCN)">
<SelectParameters>
<asp:ControlParameter Name="DCN" ControlID="GridView2"/>
</SelectParameters>
</asp:SqlDataSource>
This is the code behind file for the gridview page. 这是gridview页面文件的代码。
protected void Link_buttonClick(object sender, EventArgs e)
{
paneldetails.Visible = true;
detailsvw.Visible = true;
// do I need to add any thing at here
}
I am not able to get the data into details view here. 我无法在此处将数据放入详细信息视图。 When I click on any cell in the first column it shows the details view in panel. 当我单击第一列中的任何单元格时,它将在面板中显示详细信息视图。
How do I get the details view to display the data from the clicked row? 如何获取详细信息视图以显示单击的行中的数据?
实现主从关系的简单方法是将DataKeyNames="DCN"
(与您的情况有关)添加到第一个GridView并将其作为“详细信息”表单中的“参数”引用:请参见此处的示例: http:// www。 vkinfotek.com/detailsview/gridview-detailsview-master-detail-example.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.