Hi.
I am using a radgrid in an update panel. When I click the edit button, the radgrid disappears and when i refresh the page, it reappears in edit mode as requested initially. I have tried removing the update panel, and it doesn't make any difference.
Any help would be appreciated.
I am using a radgrid in an update panel. When I click the edit button, the radgrid disappears and when i refresh the page, it reappears in edit mode as requested initially. I have tried removing the update panel, and it doesn't make any difference.
Any help would be appreciated.
6 Answers, 1 is accepted
0
Hi calm_boy,
I suspect that you are using simple data-binding with DataBind() and nothing data-binds the grid on post-back.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I suspect that you are using simple data-binding with DataBind() and nothing data-binds the grid on post-back.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Princy
Top achievements
Rank 2
answered on 23 Apr 2008, 01:02 PM
Hi calm_boy,
Go through the following demo link to get details about AdvanceDataBinding techniques.
Advanced data-binding
Thanks
Princy.
Go through the following demo link to get details about AdvanceDataBinding techniques.
Advanced data-binding
Thanks
Princy.
0

calm_boy
Top achievements
Rank 1
answered on 23 Apr 2008, 01:43 PM
Yes. I have found out that I have to use the advanced data binding approach. But then, when I use the NeedDataSource event, it doesn't work either, so what am I supposed to do?
0

calm_boy
Top achievements
Rank 1
answered on 23 Apr 2008, 03:00 PM
I have found a solution.
I attach a datasource to the radgrid which i then populate dynamically in my code behind file. That way, it thinks it has a datasource all the time.
I attach a datasource to the radgrid which i then populate dynamically in my code behind file. That way, it thinks it has a datasource all the time.
0

SchaF
Top achievements
Rank 1
answered on 26 Jun 2013, 04:35 PM
Can someone explain to me why this is happening. I have my NeedDataSource event. When the page intially loads, I make a trip to the DB to get the table, then bind it using simple binding, ie radGrid.DataSource = object; radGrid.DataBdind(); Then when I click the edit button, the edit box pops up, I make my changes and hit update, and it fires the NeedDataSource event again, and then when it gets back to the page, my changes are gone. How do I save these changes? Where do I get the values that were edited. If the NeedDatasource is rebinding on the edit/update, then how am I ever supposed to get the users changes?
0

Princy
Top achievements
Rank 2
answered on 27 Jun 2013, 06:27 AM
Hi Schaf,
I guess you want to perform the Edit/Insert/Delete operation using Server side code and NeedDataSource event. Please have a look at the following example code snippet.
ASPX:
C#:
Thanks,
Princy
I guess you want to perform the Edit/Insert/Delete operation using Server side code and NeedDataSource event. Please have a look at the following example code snippet.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowPaging
=
"true"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
OnInsertCommand
=
"RadGrid1_InsertCommand"
OnDeleteCommand
=
"RadGrid1_DeleteCommand"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"OrderID"
CommandItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
/>
<
telerik:GridBoundColumn
HeaderText
=
"OrderID"
DataField
=
"OrderID"
UniqueName
=
"OrderID"
/>
<
telerik:GridBoundColumn
HeaderText
=
"EmployeeID"
DataField
=
"EmployeeID"
UniqueName
=
"EmployeeID"
/>
<
telerik:GridBoundColumn
HeaderText
=
"OrderDate"
DataField
=
"OrderDate"
UniqueName
=
"OrderDate"
/>
<
telerik:GridBoundColumn
HeaderText
=
"ShipName"
DataField
=
"ShipName"
UniqueName
=
"ShipName"
/>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditCommandColumn"
/>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
C#:
public
static
string
connection = WebConfigurationManager.ConnectionStrings[
"ConnectionString"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(connection);
public
SqlCommand SqlCommand =
new
SqlCommand();
DataTable dt1 =
new
DataTable();
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
string
selectQuery1 =
"SELECT [OrderID], [CustomerID], [EmployeeID], [OrderDate], [ShipName] FROM [Orders]"
;
SqlDataAdapter adapter1 =
new
SqlDataAdapter(selectQuery1, conn);
conn.Open();
adapter1.Fill(dt1);
conn.Close();
RadGrid1.DataSource = dt1;
}
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
string
OrderID = edit.GetDataKeyValue(
"OrderID"
).ToString();
TextBox txt = (TextBox)edit[
"EmployeeID"
].Controls[0];
TextBox txt1 = (TextBox)edit[
"OrderDate"
].Controls[0];
TextBox txt2 = (TextBox)edit[
"ShipName"
].Controls[0];
conn.Open();
string
query =
"UPDATE Orders SET EmployeeID ='"
+ txt.Text +
"', OrderDate='"
+ txt1.Text +
"',ShipName='"
+ txt2.Text +
"' WHERE OrderID = '"
+ OrderID +
"'"
;
SqlCommand cmd =
new
SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}
protected
void
RadGrid1_InsertCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.Item
is
GridEditableItem )
{
GridEditableItem edit = (GridEditableItem)e.Item;
TextBox tx=(TextBox)edit[
"OrderID"
].Controls[0];
TextBox txt = (TextBox)edit[
"EmployeeID"
].Controls[0];
TextBox txt1 = (TextBox)edit[
"OrderDate"
].Controls[0];
TextBox txt2 = (TextBox)edit[
"ShipName"
].Controls[0];
conn.Open();
string
query =
"INSERT into Orders (OrderID,EmployeeID,OrderDate,ShipName ) VALUES ('"
+ tx.Text+
"','"
+ txt.Text +
"','"
+ txt1.Text +
"','"
+ txt2.Text +
"')"
;
SqlCommand cmd =
new
SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}
protected
void
RadGrid1_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.Item
is
GridEditableItem)
{
GridEditableItem edit = (GridEditableItem)e.Item;
string
OrderID = edit.GetDataKeyValue(
"OrderID"
).ToString();
conn.Open();
string
query =
"DELETE from Orders Where OrderID = '"
+ OrderID +
"'"
;
SqlCommand cmd =
new
SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
}
}
Thanks,
Princy