Poster une réponse à un sujet: Gridvieuw
Attention, ce sujet est un sujet ancien (4321 jours sans réponse)
lefvl
Et dire qu'on trouvait l'assembler compliqué....
kayumba
j'ai une grid qui contient un chocbox dynamique. Donc quand je récupére la liste des rayons ça s'affiche très bien mais au moment je fais un test pour tous les checkBox chequé pour les supprimer j'ai un message d'erreur. Est ce que DataKeyNames doit absolument être un entier ou peu importe.

Voici mon code :

<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="CheckBoxField.aspx.cs" Inherits="EnhancedGridView_CheckBoxField" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<h2>
Selection Via a Column of Checkboxes</h2>
<p>
<asp:Button ID="CheckAll" runat="server" Text="Check All" OnClick="CheckAll_Click" />
 
<asp:Button ID="UncheckAll" runat="server" Text="Uncheck All" OnClick="UncheckAll_Click" /></p>
<p>
<asp:GridView ID="Products" runat="server" AutoGenerateColumns="False" DataKeyNames="S_ID_RAYON"
DataSourceID="ProductsDataSource" AllowPaging="True"
EnableViewState="False" onselectedindexchanged="Products_SelectedIndexChanged">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="ProductSelector" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="NOM" HeaderText="Rayon" />

</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ProductsDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="getAllRadius"
TypeName="AuthDataManager">
</asp:ObjectDataSource>
</p>
<p>
<asp:Button ID="DeleteSelectedProducts" runat="server" Text="Delete Selected Products" OnClick="DeleteSelectedProducts_Click" />
</p>
<p>
<asp:Label ID="DeleteResults" runat="server" EnableViewState="False" Visible="False"></asp:Label>
</p>
</asp:Content>


[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObje- ctMethodType.Select, true)]
public static ArrayList getAllRadius(string page)
{
SqlCommand command = null;

SqlConnection conn = AuthDataManager.getconnection();
if (page.Equals("1")) {

command = new SqlCommand("SELECT NOM, S_ID_RAYON FROM STOCK S, RAYONS R WHERE S.S_ID_RAYON=R.ID AND S_ANNIV = 1 AND S_WEB = 1 GROUP BY NOM, S_ID_RAYON", conn);
SqlDataReader rdr = command.ExecuteReader();

ArrayList radius = new ArrayList();
while (rdr.Read())

{
radius.Add(rdr["NOM"].ToString());
radius.Add(rdr["S_ID_RAYON"].ToString());
}
return radius;
}
}
}

bool atLeastOneRowDeleted = false;

// Iterate through the Products.Rows property
foreach (GridViewRow row in Products.Rows)
{
// Access the CheckBox
CheckBox cb = (CheckBox)row.FindControl("ProductSelector");
if (cb != null && cb.Checked)
{
// Delete row! (Well, not really...)
atLeastOneRowDeleted = true;

// First, get the ProductID for the selected row
int productID = Convert.ToInt32(Products.DataKeys[row.RowIndex].Value);

// "Delete" the row
DeleteResults.Text += string.Format("This would have deleted ProductID {0}<br />", productID);

//... To actually delete the product, use ...
//ProductsBLL productAPI = new ProductsBLL();
//productAPI.DeleteProduct(productID);
//............................................
}



j'ai une erreur au niveau de cette ligne : int productID = Convert.ToInt32(Products.DataKeys[row.RowIndex].Value); au niveau de DataKeyNames j'ai mis S_ID_RAYON mais ça marche toujours paas.

J'Attends votre aide svp. Bien à vous
Catégorie:  






Ada
CSS
Cobol
CPP
HTML
Fortran
Java
JavaScript
Pascal
Perl
PHP
Python
SQL
VB
XML
Anon URL
DailyMotion
eBay
Flickr
FLV
Google Video
Google Maps
Metacafe
MP3
SeeqPod
Veoh
Yahoo Video
YouTube
6px
8px
10px
12px
14px
16px
18px
Informaticien.be - © 2002-2024 AkretioSPRL  - Generated via Kelare
The Akretio Network: Akretio - Freedelity - KelCommerce - Votre publicité sur informaticien.be ?