我在页面上有两个网格视图 第一个数据网格(requestgrid)通过使用存储过程填充,该存储过程具有参数,该参数由查询字符串提供。
当我在第一个datagrid中选择一行时,只需要显示页面中的其他网格。我可以使用下面的代码从选择中获取请求
void Requesttbl_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("clickrequestid"))
{
Requesttbl.Visible = false;
int requestid = (int)e.CommandArgument;
}
}
我的问题是如何使用此requestid将其作为参数传递给第二个gridview
下面的代码是我在标记页面中的第二个网格视图代码
<asp:GridView ID="SelectedReports" runat="server" AutoGenerateColumns="False"
DataSourceID="showselectedreports" EnableModelValidation="True">
<Columns>
<asp:BoundField DataField="Requestid" HeaderText="Requestid"
SortExpression="Requestid" />
<asp:BoundField DataField="rptdesctext" HeaderText="rptdesctext"
SortExpression="rptdesctext" />
<asp:BoundField DataField="Completeddt" HeaderText="Completeddt"
SortExpression="Completeddt" />
<asp:BoundField DataField="Analyst" HeaderText="Analyst" ReadOnly="True"
SortExpression="Analyst" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="showselectedreports" runat="server"
ConnectionString="<%$ ConnectionStrings:UnderWritingConnectionString %>"
SelectCommand="ShowCustomerSelectedRequests"
SelectCommandType="StoredProcedure">
<SelectParameters>
how do i use the requestid as a parameter here**strong text**
</SelectParameters>
</asp:SqlDataSource>
提前致谢
答案 0 :(得分:0)
此示例可能对您有所帮助,因为我从一个网格视图中获取值CountryID并在所选国家/地区ID上填充其他ID,并根据您的要求进行更改。
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CountryID" DataSourceID="SqlDataSource1"
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="CountryID" HeaderText="CountryID" ReadOnly="True"
SortExpression="CountryID" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [CountryID], [Country] FROM [Tbl_Country]">
</asp:SqlDataSource>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="CountryID" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="CountryID" HeaderText="CountryID" ReadOnly="True"
SortExpression="CountryID" />
<asp:BoundField DataField="Country" HeaderText="Country"
SortExpression="Country" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT * FROM [Tbl_Country] WHERE ([CountryID] = @CountryID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="CountryID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>