EditItemTemplate e GridView

mercoledì 05 novembre 2008 - 12.17

1djluigi Profilo | Newbie

Ragazzi non riesco a visualizzare la textbox associata alla GridView nell'EditItemTemplate...Questo è il codice....Una spiegazione veloce..la tabella si chiama Categorie (Id, Nome e in Tipo ci sono gli elementi totali) il binding lo faccio da dll...sul binding non ci sono problemi perchè l'ho controllato e funziona perfettamente...il problema è il GridRowEditing a cui ho riassociato il binding del pageload pensando che non fosse valorizzato il bind<nome> della textbox2

<%@ Page Language="C#" MasterPageFile="~/Default.master" Title="Your Name Here | Admin"
CodeFile="Albums.aspx.cs" Inherits="Admin_Albums_aspx" %>

<asp:content id="Content1" contentplaceholderid="Main" runat="server">

<div class="shim column"></div>

<div class="page" id="admin-albums">

<div id="sidebar">
<h3>Add New Album</h3>
<p>Before uploading your pictures, create an album to organize your pictures.</p>
<p>
<asp:TextBox ID="TextBox1" Runat="server" Width="200" Text='<%# Bind("Nome") %>' CssClass="textfield" />
<asp:ImageButton ID="ImageButton1" Runat="server" CommandName="Insert" skinid="add" OnClick="ImageButton1_Click"/>

</p>


</div>

<div id="content">
<h3>Your Albums</h3>

<p>The following are the albums currently on your site. Click <b>Edit</b> to modify the pictures in each
album. Click <b>Delete</b> to permanently remove the album and all of its pictures</p>

<asp:gridview id="GridView1" runat="server" datakeynames="Id" cellpadding="6"
autogeneratecolumns="False" BorderStyle="None" BorderWidth="0px" width="420px" showheader="false" EnableViewState="False" OnRowEditing="GridView1_RowEditing" >
<EmptyDataTemplate>
You currently have no albums.
</EmptyDataTemplate>
<EmptyDataRowStyle CssClass="emptydata"></EmptyDataRowStyle>
<columns>
<asp:TemplateField>
<ItemStyle Width="116px" />
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" class="photo-frame">
<tr>
<td class="topx--"></td>
<td class="top-x-"></td>
<td class="top--x"></td>
</tr>
<tr>
<td class="midx--"></td>
<td><a href='Photos.aspx?IdCategorie=<%# Eval("Id") %>'>
<img src="../Handler.ashx?IdCategorie=<%# Eval("Id") %>&Size=S" class="photo_198" style="border:4px solid white" alt="Sample Photo from Album Number <%# Eval("Id") %>" /></a></td>
<td class="mid--x"></td>
</tr>
<tr>
<td class="botx--"></td>
<td class="bot-x-"></td>
<td class="bot--x"></td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemStyle Width="280px" />
<ItemTemplate>
<div style="padding:8px 0;">
<b><%# Server.HtmlEncode(Eval("Nome").ToString()) %></b><br />
<%# Eval("Tipo") %> Photo(s)<asp:Label ID="Label1" Runat="server"></asp:Label>
</div>
<div style="width:100%;text-align:right;">
<asp:ImageButton ID="ImageButton2" Runat="server" CommandName="Edit" SkinID="rename" />
<a href='<%# "Photos.aspx?IdCategorie=" + Eval("Id") %>'><asp:image ID="Image1" runat="Server" skinid="edit" /></a>
<asp:ImageButton ID="ImageButton3" Runat="server" CommandName="Delete" SkinID="delete" />
</div>
</ItemTemplate>
<EditItemTemplate>
<div style="padding:8px 0;">
<asp:TextBox ID="TextBox2" Runat="server" Width="160px" CssClass="textfield" Text='<%# Bind("Nome") %>' />
</div>
<div style="width:100%;text-align:right;">
<asp:ImageButton ID="ImageButton4" Runat="server" CommandName="Update" SkinID="save" />
<asp:ImageButton ID="ImageButton5" Runat="server" CommandName="Cancel" SkinID="cancel" />
</div>
</EditItemTemplate>
</asp:TemplateField>
</columns>
</asp:gridview>
</div>

</div>
</asp:content>

CODICE -------------------------------------------------------------------------------------------------------------
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Admin_Albums_aspx : System.Web.UI.Page {

protected void Page_Load(object sender, EventArgs e)
{
List<Categorie> lista = new List<Categorie>();
lista = PhotoManagerServices.GetCategorie();

this.GridView1.DataSource = lista;
GridView1.DataBind();

}

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
string Nome = TextBox1.Text;
bool b = false;
b = PhotoManagerServices.AddCategorie(Nome);
}


protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{

List<Categorie> lista = new List<Categorie>();
lista = PhotoManagerServices.GetCategorie();

this.GridView1.DataSource = lista;
GridView1.DataBind();

}

}

Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2023
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5