52 messaggi dal 13 marzo 2002
Sono riuscito a risolvere e lo posto. Forse si può fare di meglio ma funziona.

Codice aspx:

<asp:GridView ID="GVArticoli" runat="server" AutoGenerateColumns="False" BackColor="White"
BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4"
DataKeyNames="IDArticolo" DataSourceID="DSArticoli" GridLines="Horizontal" Visible="False" OnRowDataBound="GVArticoli_RowDataBound">
<FooterStyle BackColor="White" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="IDArticolo" SortExpression="IDArticolo">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("IDArticolo") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("IDArticolo") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
&nbsp;
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="IDImg" HeaderText="IDImg" SortExpression="IDImg" Visible="False" />
<asp:TemplateField HeaderText="Cod. Serie" SortExpression="Cser">
<EditItemTemplate>
&nbsp;<asp:DropDownList ID="ddlCser" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlCser_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
<HeaderStyle Wrap="False" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Cser") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
&nbsp; &nbsp;&nbsp;
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cod. Art." SortExpression="Cart">
<EditItemTemplate>
&nbsp;<asp:DropDownList ID="ddlCart" runat="server" AutoPostBack="True">
</asp:DropDownList>
</EditItemTemplate>
<HeaderStyle Wrap="False" />
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("Cart") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
&nbsp;
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" Visible="False" />
<asp:TemplateField HeaderText="Descrizione" SortExpression="DesArticolo">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DesArticolo") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("DesArticolo") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
&nbsp;
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Prezzo" HeaderText="Prezzo" SortExpression="Prezzo" ReadOnly="True" />
<asp:TemplateField HeaderText="Misure" SortExpression="Misure">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Misure") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Misure") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
&nbsp;
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantit&#224;" SortExpression="Quantita">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Quantita") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Quantita") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
&nbsp;
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tipo Gest." SortExpression="tg">
<FooterTemplate>
&nbsp;
</FooterTemplate>
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("tg") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowSelectButton="True" />
</Columns>
<RowStyle BackColor="White" ForeColor="#333333" Font-Names="Tahoma" Font-Size="10pt" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
</asp:GridView>

Code Behind:

protected void GVArticoli_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{

DropDownList ddlCser = (DropDownList)e.Row.FindControl("ddlCser");

ddlCser.DataSource = DSCser;
ddlCser.DataTextField = "cser";
ddlCser.DataValueField = "cser";
ddlCser.DataBind();

//Seleziono lo Cser appropriato
string CserCorrente = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "cser"));
ListItem li = ddlCser.Items.FindByValue(CserCorrente);
if (li != null)
{
li.Selected = true;
}

// Popolo la DDL dei Cart in base allo Cser selezionato
string CartCorrente = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "cart"));

DropDownList ddlCart = (DropDownList)e.Row.FindControl("ddlCart");

PopolaCart(ddlCart, ddlCser, CartCorrente, CserCorrente);

if (CserCorrente == "")
{
CserCorrente = ddlCser.SelectedItem.Value;
CartCorrente = ddlCart.SelectedItem.Value;
}
}
}

protected void ddlCser_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlCser = (DropDownList)sender;
GridViewRow gvr = (GridViewRow)ddlCser.Parent.Parent;
DropDownList ddlCart = (DropDownList)gvr.FindControl("ddlCart");

PopolaCart(ddlCart, ddlCser, "", "");

string CartCorrente = ddlCart.SelectedItem.Value;
string CserCorrente = ddlCser.SelectedItem.Value;

}

private void PopolaCart(DropDownList ddlCart, DropDownList ddlCser, string CartCorrente, string CserCorrente)
{
DSCart.SelectParameters["Cser_sel"].DefaultValue = ddlCser.SelectedValue;

ddlCart.DataSource = DSCart;
ddlCart.DataTextField = "cart";
ddlCart.DataValueField = "cart";
ddlCart.DataBind();

// ora seleziono l'appropriato Cart
ListItem li2 = ddlCart.Items.FindByValue(CartCorrente);
if (li2 != null)
{
li2.Selected = true;
}

}
2 messaggi dal 04 giugno 2006
umbtaf ha scritto:
Sono riuscito a risolvere e lo posto. Forse si può fare di meglio ma funziona.

Codice aspx:

Code Behind:

private void PopolaCart(DropDownList ddlCart, DropDownList ddlCser, string CartCorrente, string CserCorrente)
{
DSCart.SelectParameters["Cser_sel"].DefaultValue = ddlCser.SelectedValue;

ddlCart.DataSource = DSCart;
ddlCart.DataTextField = "cart";
ddlCart.DataValueField = "cart";
ddlCart.DataBind();

// ora seleziono l'appropriato Cart
ListItem li2 = ddlCart.Items.FindByValue(CartCorrente);
if (li2 != null)
{
li2.Selected = true;
}

}


Excuse me, what means ["Cser_sel"]????
2 messaggi dal 04 giugno 2006
Mi codice :

<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1" EmptyDataText="Il n'y a aucun enregistrement de données à afficher." OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True" SortExpression="id" Visible="False" />
<asp:BoundField DataField="userid" HeaderText="userid" SortExpression="userid" Visible="False" />
<asp:BoundField DataField="date" HeaderText="date" SortExpression="date" />

<asp:TemplateField HeaderText="projet" SortExpression="projet">
<EditItemTemplate>
<asp:DropDownList ID="ddlprojet" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlproj_SelectedIndexChanged">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("projet") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="activite" SortExpression="activite">
<EditItemTemplate>
<asp:DropDownList ID="ddlactivite" runat="server" AutoPostBack="True">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("activite") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="duree" HeaderText="duree" SortExpression="duree" />
<asp:BoundField DataField="commentaire" HeaderText="commentaire" SortExpression="commentaire" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ldapConnectionString1 %>"
DeleteCommand="DELETE FROM [cra] WHERE [id] = @id" InsertCommand="INSERT INTO [cra] ([userid], [date], [projet], [activite], [duree], [commentaire]) VALUES (@userid, @date, @projet, @activite, @duree, @commentaire)"
ProviderName="<%$ ConnectionStrings:ldapConnectionString1.ProviderName %>" SelectCommand="SELECT [id], [userid], [date], [projet], [activite], [duree], [commentaire] FROM [cra]"
UpdateCommand="UPDATE [cra] SET [userid] = @userid, [date] = @date, [projet] = @projet, [activite] = @activite, [duree] = @duree, [commentaire] = @commentaire WHERE [id] = @id">
<InsertParameters>
<asp:Parameter Name="userid" Type="String" />
<asp:Parameter Name="date" Type="String" />
<asp:Parameter Name="projet" Type="String" />
<asp:Parameter Name="activite" Type="String" />
<asp:Parameter Name="duree" Type="Int32" />
<asp:Parameter Name="commentaire" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="userid" Type="String" />
<asp:Parameter Name="date" Type="String" />
<asp:Parameter Name="projet" Type="String" />
<asp:Parameter Name="activite" Type="String" />
<asp:Parameter Name="duree" Type="Int32" />
<asp:Parameter Name="commentaire" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="DSProjet" runat="server" ConnectionString="<%$ ConnectionStrings:ldapConnectionString1 %>" SelectCommand="SELECT DISTINCT [projet] FROM [proact]"></asp:SqlDataSource>

<asp:SqlDataSource ID="DSactivite" runat="server" ConnectionString="<%$ ConnectionStrings:ldapConnectionString1 %>" SelectCommand="SELECT [activite] FROM [proact] WHERE ([projet] = @projet)">
<SelectParameters>
<asp:Parameter Name="projet" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

</form>

Code behind :

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList ddlprojet = (DropDownList)e.Row.FindControl("ddlprojet");

ddlprojet.DataSource = DSProjet;
ddlprojet.DataTextField = "projet";
ddlprojet.DataValueField = "projet";
ddlprojet.DataBind();

//Seleziono lo Cser appropriato
string nomprojet = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "projet"));
ListItem li = ddlprojet.Items.FindByValue(nomprojet);
if (li != null)
{
li.Selected = true;
}

// Popolo la DDL dei Cart in base allo Cser selezionato
string nomactivite = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "activite"));

DropDownList ddlactivite = (DropDownList)e.Row.FindControl("ddlactivite");

PopolaCart(ddlactivite, ddlprojet, nomactivite, nomprojet);

if (nomprojet == "")
{
nomprojet = ddlprojet.SelectedItem.Value;
nomactivite = ddlactivite.SelectedItem.Value;
}
}
}
protected void ddlproj_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlprojet = (DropDownList)sender;
GridViewRow gvr = (GridViewRow)ddlprojet.Parent.Parent;
DropDownList ddlactivite = (DropDownList)gvr.FindControl("ddlprojet");

PopolaCart(ddlactivite, ddlprojet, "", "");

string nomprojet = ddlprojet.SelectedItem.Value;
string nomactivite = ddlactivite.SelectedItem.Value;
}

private void PopolaCart(DropDownList ddlactivite, DropDownList ddlprojet, string nomactivite, string nomprojet)
{
DSactivite.SelectParameters["???"].DefaultValue = ddlprojet.SelectedValue;

ddlactivite.DataSource = DSactivite;
ddlactivite.DataTextField = "activite";
ddlactivite.DataValueField = "activite";
ddlactivite.DataBind();

// ora seleziono l'appropriato Cart
ListItem li2 = ddlactivite.Items.FindByValue(nomactivite);
if (li2 != null)
{
li2.Selected = true;
}

}
Modificato da cnguyen il 04 giugno 2006 13.18 -
52 messaggi dal 13 marzo 2002
My sqldatasources:

<asp:SqlDataSource ID="DSArticoli" runat="server" ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionSQL %>" DeleteCommand="DELETE FROM [Articoli] WHERE [IDArticolo] = @original_IDArticolo AND [IDImg] = @original_IDImg AND [Cser] = @original_Cser AND [Cart] = @original_Cart AND [Code] = @original_Code AND [DesArticolo] = @original_DesArticolo AND [Prezzo] = @original_Prezzo AND [Misure] = @original_Misure AND [Quantita] = @original_Quantita"
InsertCommand="INSERT INTO [Articoli] ([IDArticolo], [IDImg], [Cser], [Cart], [Code], [DesArticolo], [Prezzo], [Misure], [Quantita]) VALUES (@IDArticolo, @IDImg, @Cser, @Cart, @Code, @DesArticolo, @Prezzo, @Misure, @Quantita)"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT Articoli.IDArticolo, Articoli.IDImg, Articoli.Cser, Articoli.Cart, Articoli.Code, Articoli.DesArticolo, Articoli.Prezzo, Articoli.Misure, Articoli.Quantita, CASE WHEN dbo.artmagw.tg IS NULL THEN '' ELSE dbo.artmagw.tg END AS tg FROM Articoli LEFT OUTER JOIN artmagw ON Articoli.Cart = artmagw.cart AND Articoli.Cser = artmagw.cser WHERE (Articoli.IDImg = @IDImg)"
UpdateCommand="UPDATE Articoli SET Cser = @Cser, Cart = @Cart, Code = SUBSTRING(@Cser + ' ', 1, 4) + SUBSTRING(@Cart + ' ', 1, 10), DesArticolo = @DesArticolo, Misure = @Misure, Quantita = @Quantita WHERE (IDArticolo = @original_IDArticolo)">
<DeleteParameters>
<asp:Parameter Name="original_IDArticolo" Type="Int32" />
<asp:Parameter Name="original_IDImg" Type="Int32" />
<asp:Parameter Name="original_Cser" Type="String" />
<asp:Parameter Name="original_Cart" Type="String" />
<asp:Parameter Name="original_Code" Type="String" />
<asp:Parameter Name="original_DesArticolo" Type="String" />
<asp:Parameter Name="original_Prezzo" Type="Decimal" />
<asp:Parameter Name="original_Misure" Type="String" />
<asp:Parameter Name="original_Quantita" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Cser" Type="String" ConvertEmptyStringToNull="False" DefaultValue="" />
<asp:Parameter Name="Cart" Type="String" ConvertEmptyStringToNull="False" DefaultValue="" />
<asp:Parameter Name="DesArticolo" Type="String" />
<asp:Parameter Name="Misure" Type="String" ConvertEmptyStringToNull="False" DefaultValue="" />
<asp:Parameter Name="Quantita" Type="Int32" />
<asp:Parameter Name="original_IDArticolo" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GVImmagini" Name="IDImg" PropertyName="SelectedValue"
Type="Int32" DefaultValue="6" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="IDArticolo" Type="Int32" />
<asp:Parameter Name="IDImg" Type="Int32" />
<asp:Parameter Name="Cser" Type="String" />
<asp:Parameter Name="Cart" Type="String" />
<asp:Parameter Name="Code" Type="String" />
<asp:Parameter Name="DesArticolo" Type="String" />
<asp:Parameter Name="Prezzo" Type="Decimal" />
<asp:Parameter Name="Misure" Type="String" />
<asp:Parameter Name="Quantita" Type="Int32" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="DSCart" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionSQL %>" SelectCommand="GAListaCart" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="Cser_sel" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="DSCser" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionSQL %>"
SelectCommand="GAListaCser" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.