Hi ,
I need to perform radgrid insert operation with external textbox and button.I have one rad grid with data from sql server.I Placed textbox and button completely not related with radgrid.I need to insert values from external textbox to radgrid with external button click.
Can anyone pls help me on this
I need to perform radgrid insert operation with external textbox and button.I have one rad grid with data from sql server.I Placed textbox and button completely not related with radgrid.I need to insert values from external textbox to radgrid with external button click.
Can anyone pls help me on this
5 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 27 Nov 2012, 09:49 AM
Hi,
Please take a look into the following code snippet I tried to insert new item in the RadGrid on an external button click without opening the insert form of RadGrid.
C#:
Thanks,
Shinu.
Please take a look into the following code snippet I tried to insert new item in the RadGrid on an external button click without opening the insert form of RadGrid.
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
OrderValue = TextBox1.Text;
SqlConnection.Open();
string
insertQuery =
"insert into Orders (OrderID) values ('"
+ OrderValue +
"')"
;
//query to insert TextBox text in Database
SqlCommand.CommandText = insertQuery;
SqlCommand.Connection = SqlConnection;
SqlCommand.ExecuteNonQuery();
SqlConnection.Close();
RadGrid1.Rebind();
}
Thanks,
Shinu.
0
ALEX
Top achievements
Rank 1
answered on 27 Nov 2012, 01:29 PM
I tried this ,only textbox values inserted in sql db ,the values not binded and shown in radgrid.
0
Shinu
Top achievements
Rank 2
answered on 28 Nov 2012, 06:37 AM
Hi Vignesh,
Please make sure that you are Rebinding the RadGrid in the Button Click event and the inserted DataField is present in the RadGrid. After rebind, the newly inserted data also will be added in the RadGrid from the database. Check the entire code snippet I tried.
ASPX:
C#:
Thanks,
Shinu.
Please make sure that you are Rebinding the RadGrid in the Button Click event and the inserted DataField is present in the RadGrid. After rebind, the newly inserted data also will be added in the RadGrid from the database. Check the entire code snippet I tried.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
>
<
MasterTableView
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"OrderID"
HeaderText
=
"OrderID"
SortExpression
=
"OrderID"
></
telerik:GridBoundColumn
>
</
columns
>
<
MasterTableView
>
</
telerik:RadGrid
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
></
asp:TextBox
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
OnClick
=
"button1_Click"
/>
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
string
OrderValue = TextBox1.Text;
SqlConnection.Open();
string
insertQuery =
"insert into Orders (OrderID) values ('"
+ OrderValue +
"')"
;
//query to insert TextBox text in Database
SqlCommand.CommandText = insertQuery;
SqlCommand.Connection = SqlConnection;
SqlCommand.ExecuteNonQuery();
SqlConnection.Close();
RadGrid1.Rebind();
// Rebind the RadGrid
}
Thanks,
Shinu.
0
ALEX
Top achievements
Rank 1
answered on 28 Nov 2012, 10:06 AM
how for update and delete and also radgrid load data in pageload
0
Hello Peter,
You could use the same approach as the one suggested by Shinu, just need to pass a different query string. For example if you would like to delete an item you have to pass the following query string:
Greetings,
Kostadin
the Telerik team
You could use the same approach as the one suggested by Shinu, just need to pass a different query string. For example if you would like to delete an item you have to pass the following query string:
string
deleteQuery =
"DELETE FROM [Products] WHERE [ProductID] = ('"
+ ProductID+
"')"
;
//query to item from Database
SqlCommand.CommandText = deleteQuery ;
Greetings,
Kostadin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.