471,065 Members | 1,322 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,065 software developers and data experts.

Getting null value in datakeynames while Inserting ..

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....

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridView2" DataSourceID="SqlDataSource2" DataKeyNames="AlertID,ItemID" AutoGenerateColumns="False" runat="server"  Width="839px" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True">
  2.                     <Columns>
  3.                     <asp:BoundField DataField="AlertID" HeaderText="AlertID" SortExpression="AlertID" >
  4.                         <ItemStyle Width="10px" />
  5.                         <HeaderStyle Width="10px" />
  6.                     </asp:BoundField>
  7.                     <asp:BoundField DataField="OPCServer" HeaderText="Server" SortExpression="OPCServer" >
  8.                         <ItemStyle Width="40px" />
  9.                     </asp:BoundField>
  10.                     <asp:BoundField DataField="OPCItem" HeaderText="Item" SortExpression="OPCItem" />
  11.                     <asp:BoundField DataField="AlertType" HeaderText="AlertType" SortExpression="AlertType" />
  12.                     <asp:BoundField DataField="AlertValue" HeaderText="AlertValue" SortExpression="AlertValue" />
  13.  
  14.                      <asp:BoundField DataField="Active" HeaderText="Active" SortExpression="Active" />
  15.                       <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
  16.                       <asp:BoundField DataField="AlertGroupAssignmentID" HeaderText="AlertGroupAssignmentID" SortExpression="AlertGroupAssignmentID" Visible="False" />
  17.                     <asp:TemplateField>
  18.                     <ItemTemplate>
  19.                     <asp:CheckBox runat="server" ID="chkbox"/>
  20.                     </ItemTemplate>
  21.                     </asp:TemplateField>
  22.  
  23.                     </Columns>
  24.            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  25.            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  26.            <EditRowStyle BackColor="#999999" />
  27.            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
  28.            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
  29.            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
  30.            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
  31.  
  32.  
  33.                     </asp:GridView>
  34.  
  35.  
  36.  <asp:SqlDataSource
  37.         id="SqlDataSource2"
  38.         SelectCommand="Allalertgroupdata" InsertCommand="insert into AlertGroupAssignment (OPCItemID,OPCAlertID,AlertGroupID) values (@OPCItemID,@OPCAlertID,@AlertGroupID)"
  39.  
  40.         ConnectionString="<%$ ConnectionStrings:pumaalert %>"
  41.         Runat="server" SelectCommandType="StoredProcedure">
  42.         <SelectParameters>
  43.        <asp:SessionParameter SessionField="alertgpid" Name="alertgroup" />
  44.         <asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="filtergrp"  />
  45.         <asp:ControlParameter ControlID="TextBox1" PropertyName="Text" Name="criteria" />
  46.         </SelectParameters>
  47.        <InsertParameters>
  48.  
  49.        <asp:ControlParameter Name="OPCAlertID" ControlID="GridView2" PropertyName='SelectedDataKey("AlertID")' Type="Int32"  />
  50.        <asp:ControlParameter Name="OPCItemID" ControlID="GridView2" PropertyName='SelectedDataKey("ItemID")' Type="Int32" />
  51.         <asp:SessionParameter Name="AlertGroupID" Type="Int32"  SessionField="alertgpid" />
  52.        </InsertParameters>
  53.         </asp:SqlDataSource>
  54.  
  55.          <asp:SqlDataSource
  56.         id="addalertgroup"
  57.         SelectCommand="Dropdownalertgroup"
  58.         ConnectionString="<%$ ConnectionStrings:pumaalert %>"
  59.         Runat="server" SelectCommandType="StoredProcedure">
  60.          <SelectParameters>
  61.        <asp:SessionParameter Name="alertname" Type="String" SessionField="alertgpname" />
  62.  
  63.  
  64.         </SelectParameters>
  65.        </asp:SqlDataSource>
  66.  
  67.  
  68.  Protected Sub ImageButton8_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton8.Click
  69.         For Each row As GridViewRow In GridView2.Rows
  70.  
  71.             Dim checkbox As CheckBox = CType(row.FindControl("chkbox"), CheckBox)
  72.             If checkbox.Checked Then
  73.                 SqlDataSource2.Insert()
  74.  
  75.  
  76.  
  77.             End If
  78.  
  79.  
  80.         Next
  81.  
  82.     End Sub
Jul 14 '08 #1
0 930

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Marcus | last post: by
9 posts views Thread by KDawg44 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.