google-code-prettify

星期四, 4月 21, 2011

【ASP.NET】利用 Sqldatasource 抓出 Gridview 的 SelectedDataKey

當 Gridview 設定了多個 DataKey 時
Sqldatasource 要如何取得 Selected DataKeys 中的某一個 DataKey
主要是用 ControlParameter 然後定義 PropertyNameSelectedDataKey 加上維度即可做到

<asp:ControlParameter ControlID="GridView1" Name="ServiceID" PropertyName="SelectedDataKey[0]" />




---------------------------------------------------------------------------------------------------------------------------
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" 
SelectCommand="SELECT A,B,C FROM Table WHERE A = @A And B=@B">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="A" PropertyName="SelectedDataKey[0]" />
<asp:ControlParameter ControlID="GridView1" Name="B" PropertyName="SelectedDataKey[1]" />
</SelectParameters>
</asp:SqlDataSource>
----------------------------------------------------------------------------------------------------------------------------

沒有留言 :

張貼留言