Zdravim, snazim sa prekopat Editable Nested GridView z CodeProjektu. http://www.codeproject.com/Articles/2004... Zapacilo sa mi to ale je to urobene pre AcessDB a ja to potrebujem pre SQLServer. Predpokladal som ze len zmenim kod v codebehind a pojde to Tak napr: Povodny kod pre Acess
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//Get the values stored in the text boxes
string strCompanyName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtCompanyName")).Text;
string strContactName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtContactName")).Text;
string strContactTitle = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtContactTitle")).Text;
string strAddress = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtAddress")).Text;
string strCustomerID = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblCustomerID")).Text;
try
{
//Prepare the Update Command of the DataSource control
string strSQL = "";
strSQL = "UPDATE Customers set CompanyName = '" + strCompanyName + "'" +
",ContactName = '" + strContactName + "'" +
",ContactTitle = '" + strContactTitle + "'" +
",Address = '" + strAddress + "'" +
" WHERE CustomerID = '" + strCustomerID + "'";
AccessDataSource1.UpdateCommand = strSQL;
AccessDataSource1.Update();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Customer updated successfully');</script>");
}
catch { }
}
som to upravil na
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strConnString = ConfigurationManager.ConnectionStrings["PersonalConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
//Získa hodnoty uložené v textových poliach
string strNaradie = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtNaradie")).Text;
string strKusov = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtkusov")).Text;
string strCena = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcena")).Text;
string strCenaCelkom = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcenaCelkom")).Text;
string strSklDoklad = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblIdPohybu")).Text;
try
{
//Pripraví príkaz Aktualizácia ovládacieho prvku DataSource
string strSQL = "";
strSQL = "UPDATE TempSklPohyby SET Naradie = '" + strNaradie + "'" +
",kusov = '" + strKusov + "'" +
",cena = '" + strCena + "'" +
",cenaCelkom = '" + strCenaCelkom + "'" +
" WHERE sklDoklad = '" + strSklDoklad + "'";
SqlCommand cmd = new SqlCommand(strSQL, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Položka príjemky úspešne aktualizovaná');</script>");
}
catch { }
}
Ale po stlacení tlacidla Update to vyhodí chybu Updating is not supported by data source PohybySqlDataSource unless UpdateCommand is specified v ASPX mam sice PohybySqlDataSource pre Grid kde je len SELECT
<asp:SqlDataSource ID="PohybySqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:PersonalConnectionString %>"
SelectCommand="SELECT TempSklPohyby.IdPohybu, TempSklPohyby.Naradie, TempSklPohyby.kusov, TempSklPohyby.Cena, TempSklPohyby.cenaCelkom
FROM TempSklPohyby WHERE TempSklPohyby.sklDoklad = @sklDoklad ORDER BY TempSklPohyby.IdPohybu ">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="sklDoklad" QueryStringField="Prijemka" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Ako to rozbehat ? Treba úplne vyhodiť PohybySqlDataSource a urobiť prvotne naplnenie len v CodeBehind. Alebo je treba dorobit do PohybySqlDataSource dalsi kod v ASPX stranke pre UPDATE, INSERT,DELETE... Dik za rady ... Dakujem
|