Hi,
  If you want to delete the datagrid row on the basis of composite key. As you 
mention you get the PersonId field but you are
  unable to get activityId field so add one more column "ACTIVITY ID" as make 
it hidden column so that wherever you delete the 
  row you easily get activity id from this hidden column

Krishan Kant

 
I'm having problems deleteing rows from a datagrid because the row 
uses a composite key (personID and activityID).  I can retrieve the 
value of one key but don't know how I can retrieve the value of the 
other before proceeding with the delete command - any ideas?
Here's the aspx code for the grid:

<asp:datagrid id="dgAssignedActivity" runat="server" 
ShowFooter="True" Width="650px" AutoGenerateColumns="False"
                              BorderWidth="1px" 
BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" 
CellPadding="3" GridLines="Horizontal">
                              <SelectedItemStyle Font-
Bold="True" ForeColor="#F7F7F7" 
BackColor="#738A9C"></SelectedItemStyle>
                              <AlternatingItemStyle 
BackColor="#F7F7F7"></AlternatingItemStyle>
                              <ItemStyle 
ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle>
                              <HeaderStyle Font-Size="X-
Small" Font-Bold="True" ForeColor="#F7F7F7" 
BackColor="#4A3C8C"></HeaderStyle>
                              <FooterStyle 
ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle>
                              <Columns>
                                    <asp:TemplateColumn>
                                    
      <ItemTemplate>
                                          
      <asp:LinkButton id="LinkButton2" runat="server" Text="Edit" 
Font-Size="X-Small" Height="20px" CommandName="Edit" 
CausesValidation="false">Edit</asp:LinkButton>
                                    
      </ItemTemplate>
                                    
      <EditItemTemplate>
<asp:LinkButton id="LinkButton4" runat="server" Text="Update" Font-
Size="X-Small" Height="20px" 
CommandName="Update">Update</asp:LinkButton>&nbsp; 
<asp:LinkButton id="LinkButton3" runat="server" Text="Cancel" Font-
Size="X-Small" Height="20px" 
CommandName="Cancel" 
CausesValidation="false">Cancel</asp:LinkButton>
</EditItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                    
      <ItemTemplate>
                                          
      <asp:LinkButton id="LinkButton1" runat="server" 
Text="Delete" Font-Size="X-Small" Height="20px" 
CommandName="Delete" 
CausesValidation="false">Delete</asp:LinkButton>
                                    
      </ItemTemplate>
                                    
      <FooterTemplate>
                                          
      <asp:LinkButton id="lnkAdd" runat="server" Font-Size="X-
Small" Height="20px">Add</asp:LinkButton>
                                    
      </FooterTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn 
Visible="False" HeaderText="PersonID">
                                    
      <ItemTemplate>
                                          
      <asp:Label id="lblUserID" runat="server" Visible="False" 
Width="99px"></asp:Label>
                                    
      </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn 
Visible="False" HeaderText="ActivityID">
                                    
      <ItemTemplate>
                                          
      <asp:Label id=lblActivityID runat="server" Text='<%# 
DataBinder.Eval(Container, "DataItem.pa_ActivityID") %>' 
Visible="False">
                                          
      </asp:Label>
                                    
      </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn 
HeaderText="Activities">
                                          <HeaderStyle 
Width="75px"></HeaderStyle>
                                    
      <ItemTemplate>
                                          
      <asp:Label id=lblActivities runat="server" Text='<%# 
DataBinder.Eval(Container, "DataItem.ActivityName") %>' 
Width="300px" Font-Size="X-Small">
                                          
      </asp:Label>
                                    
      </ItemTemplate>
                                    
      <FooterTemplate>
                                          
      <asp:DropDownList id="ddlActivity" runat="server" 
Width="300px" Height="20px" Font-Size="X-Small" Datasource="<%# 
GetddlActivityData %>" DataValueField="ActivityID" 
DataTextField="ActivityName">
                                          
      </asp:DropDownList>
                                    
      </FooterTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn 
HeaderText="No. of People">
                                          <HeaderStyle 
Width="50px"></HeaderStyle>
                                    
      <ItemTemplate>
                                          
      <asp:Label id="lblNoPeople" runat="server" Width="40px" Font-
Size="X-Small"></asp:Label>
                                    
      </ItemTemplate>
                                    
      <FooterTemplate>
                                          
      <asp:TextBox id="txtAddNoPeople" runat="server" Width="40px" 
Font-Size="X-Small" Height="20px"></asp:TextBox>
                                    
      </FooterTemplate>
                                    
      <EditItemTemplate>
                                          
      <asp:TextBox id="txtNoPeople" runat="server" Width="40px" 
Font-Size="X-Small" Height="20px"></asp:TextBox>
                                    
      </EditItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn 
HeaderText="Hours/person">
                                          <HeaderStyle 
Width="50px"></HeaderStyle>
                                    
      <ItemTemplate>
                                          
      <asp:Label id="lblHoursPerson" runat="server" Width="40px" 
Font-Size="X-Small" Height="20px"></asp:Label>
                                    
      </ItemTemplate>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn 
HeaderText="Name">
                                          <HeaderStyle 
Width="125px"></HeaderStyle>
                                    
      <ItemTemplate>
                                          
      <asp:Label id=lblName runat="server" Text='<%# 
DataBinder.Eval(Container, "DataItem.Name") %>' Width="158px" Font-
Size="X-Small" Height="20px">
                                          
      </asp:Label>
                                    
      </ItemTemplate>
                                    
      <FooterTemplate>
                                          
      <asp:DropDownList id=ddlAddName runat="server" Width="158px" 
Font-Size="X-Small" Height="20px" DataValueField="personID" 
DataTextField="Name" DataSource="<%# getddlNameData %>">
                                          
      </asp:DropDownList>
                                    
      </FooterTemplate>
                                    
      <EditItemTemplate>
                                          
      <asp:DropDownList id=ddlName runat="server" Width="158px" 
Font-Size="X-Small" Height="20px" OnPreRender="SetDropDownIndex" 
DataValueField="personID" Datasource="<%# GetddlNameData %>" 
DatatextField="Name">
                                          
      </asp:DropDownList>
                                    
      </EditItemTemplate>
                                    </asp:TemplateColumn>
                              </Columns>
                              <PagerStyle 
HorizontalAlign="Right" ForeColor="#4A3C8C" 
BackColor="#E7E7FF"></PagerStyle>
                        </asp:datagrid></TD>

Code behind:

Private Sub dgAssignedActivity_DeleteCommand(ByVal source As Object, 
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) 
Handles dgAssignedActivity.DeleteCommand
        
        Dim personID As Integer
                ActivityID = dgAssignedActivity.DataKeys
(e.Item.ItemIndex)
        'personID = e.Item.Cells(3)




        lblError.Text = " "
        Session("UserIdToDelete") = -1

        'Dim dtnames = DataHelper.DeleteUser(personID)
        dgAssignedActivity.ShowFooter = False
        Getdgdata()
    End Sub




---------------------------------
Yahoo! Groups Links

   To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
  
   To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
  
   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


Send instant messages to your online friends http://uk.messenger.yahoo.com 

[Non-text portions of this message have been removed]



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to