Iam get null values in the datakeynames AlertID,ItemID while executing the Insert Command....I am Inserting using Externel button Event.Here is the code of Gridiew ,Its datasource and the button event......Need help....
Code:
<asp:GridView ID="GridView2" DataSourceID="SqlDataSource2" DataKeyNames="AlertID,ItemID" AutoGenerateColumns="False" runat="server" Width="839px" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True">
<Columns>
<asp:BoundField DataField="AlertID" HeaderText="AlertID" SortExpression="AlertID" >
<ItemStyle Width="10px" />
<HeaderStyle Width="10px" />
</asp:BoundField>
<asp:BoundField DataField="OPCServer" HeaderText="Server" SortExpression="OPCServer" >
<ItemStyle Width="40px" />
</asp:BoundField>
<asp:BoundField DataField="OPCItem" HeaderText="Item" SortExpression="OPCItem" />
<asp:BoundField DataField="AlertType" HeaderText="AlertType" SortExpression="AlertType" />
<asp:BoundField DataField="AlertValue" HeaderText="AlertValue" SortExpression="AlertValue" />
<asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="AlertGroupAssignmentID" HeaderText="AlertGroupAssignmentID" SortExpression="AlertGroupAssignmentID" Visible="False" />
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkbox"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
[B]<asp:SqlDataSource
id="SqlDataSource2"
SelectCommand="Allalertgroupdata" InsertCommand="insert into AlertGroupAssignment (OPCItemID,OPCAlertID,AlertGroupID) values (@OPCItemID,@OPCAlertID,@AlertGroupID)"
ConnectionString="<%$ ConnectionStrings:pumaalert %>"
Runat="server" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter SessionField="alertgpid" Name="alertgroup" />
<asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="filtergrp" />
<asp:ControlParameter ControlID="TextBox1" PropertyName="Text" Name="criteria" />
</SelectParameters>
<InsertParameters>
<asp:ControlParameter Name="OPCAlertID" ControlID="GridView2" PropertyName='SelectedDataKey("AlertID")' Type="Int32" />
<asp:ControlParameter Name="OPCItemID" ControlID="GridView2" PropertyName='SelectedDataKey("ItemID")' Type="Int32" />
<asp:SessionParameter Name="AlertGroupID" Type="Int32" SessionField="alertgpid" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource
id="addalertgroup"
SelectCommand="Dropdownalertgroup"
ConnectionString="<%$ ConnectionStrings:pumaalert %>"
Runat="server" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="alertname" Type="String" SessionField="alertgpname" />
</SelectParameters>
</asp:SqlDataSource>[/B]
Protected Sub ImageButton8_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton8.Click
For Each row As GridViewRow In GridView2.Rows
Dim checkbox As CheckBox = CType(row.FindControl("chkbox"), CheckBox)
If checkbox.Checked Then
SqlDataSource2.Insert()
End If
Next
End Sub