Hi guys, i have a problem with my gridview contains a textbox to set a date.
<asp:gridview ID="Gridview1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
DataSourceID="AccessDataSource1" CellPadding="8" ForeColor="#333333"
GridLines="None" CellSpacing="5" Height="361px" Width="748px">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="nome" HeaderText="Nome Utente"
SortExpression="nome" >
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="titolo" HeaderText="Titolo Libro"
SortExpression="titolo" >
<ItemStyle HorizontalAlign="Center" /></asp:BoundField>
<asp:BoundField DataField="Expr1" HeaderText="Data Restituzione Prevista"
ReadOnly="True" SortExpression="Expr1" >
<ItemStyle HorizontalAlign="Center" /></asp:BoundField>
<asp:TemplateField
HeaderText="Data Restituzione" SortExpression="Expr2">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Expr2") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Expr2") %>'
AutoPostBack="True" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<SortedAscendingCellStyle BackColor="#FDF5AC" />
<SortedAscendingHeaderStyle BackColor="#4D0000" />
<SortedDescendingCellStyle BackColor="#FCF6C0" />
<SortedDescendingHeaderStyle BackColor="#820000" />
</asp:gridview>
And it is my asp.cs file:
namespace Utenti_Biblio { public partial class prestiti : System.Web.UI.Page { bool changed = false;
protected void Page_Load(object sender, EventArgs e)
{
selectRow();
}
public void selectRow()
{
foreach (GridViewRow row in this.Gridview1.Rows)
{
TextBox textBox = (TextBox)row.Cells[3].FindControl("TextBox1");
string a = textBox.Text;
if (a != "")
{
row.Cells[3].FindControl("TextBox1").Visible = false;
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
changed = true;
}
// salva
protected void Button1_Click(object sender, EventArgs e)
{
if (changed)
{
foreach (GridViewRow row in this.Gridview1.Rows)
{
TextBox textBox = (TextBox)row.Cells[3].FindControl("TextBox1");
string qry = "UPDATE b_prestiti SET data_restituzione ='" + textBox.Text + "' WHERE id_utente = '" + row.Cells[1].ToString() + "'";
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
OleDbCommand cmd = conn.CreateCommand();
OleDbDataReader reader = null;
conn.Open();
cmd.CommandText = qry;
reader = cmd.ExecuteReader();
ClientScript.RegisterStartupScript(this.GetType(), "conferma", "alert('Data Restituzione inserita!');window.location='Default.aspx';", true);
reader.Close();
conn.Close();
}
}
}
}
}
How i do to update the database when i set the date into my textbox? The query string is not correct. Thanks!