473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Editable datagrid

Hi,
I'm working on a asp.net project with a datagrid. I want the user to
be adding data into Sql database using the datagrid. So I'm using a
ListBox to do this and edit update and delete. I placed listbox in
EditItemTemplate and label in ItemTemplate. but when I try now to edit
it does not bring the lisbox but i can read the grid with the sql
content. my code actually looks like this:

public void Edit_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
}

public void Cancel_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = -1;
BindDataGrid();
}

public void Update_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.ListBox st=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[5].FindControl("lbachobj");
System.Web.UI.WebControls.ListBox st1=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[4].FindControl("lbobj");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into Object,AchievedObject where
@Object,@AchievedObject";
myCommand.Parameters.Add(new
SqlParameter("@AchievedObject",SqlDbType.Text));
myCommand.Parameters["@AchievedObject"].Value=st.SelectedValue;
myCommand.Parameters.Add(new SqlParameter("@Object",SqlDbType.Text));
myCommand.Parameters["@Object"].Value=st1.SelectedValue;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgid.EditItemIndex=-1;
BindDataGrid();
}

Thanks.

Feb 22 '07 #1
5 2194
On Feb 22, 2:36 pm, "rcoco" <nclau...@yahoo.cawrote:
Hi,
I'm working on a asp.net project with a datagrid. I want the user to
be adding data into Sql database using the datagrid. So I'm using a
ListBox to do this and edit update and delete. I placed listbox in
EditItemTemplate and label in ItemTemplate. but when I try now to edit
it does not bring the lisbox but i can read the grid with the sql
content. my code actually looks like this:

public void Edit_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();

}

public void Cancel_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = -1;
BindDataGrid();

}

public void Update_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.ListBox st=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[5].FindControl("lbachobj*");
System.Web.UI.WebControls.ListBox st1=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[4].FindControl("lbobj");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into Object,AchievedObject where
@Object,@AchievedObject";
myCommand.Parameters.Add(new
SqlParameter("@AchievedObject",SqlDbType.Text));
myCommand.Parameters["@AchievedObject"].Value=st.SelectedValue;
myCommand.Parameters.Add(new SqlParameter("@Object",SqlDbType.Text));
myCommand.Parameters["@Object"].Value=st1.SelectedValue;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgid.EditItemIndex=-1;
BindDataGrid();

}

Thanks.
By data grid i assume you are talking about GridView. By default you
cannot insert new rows from within gridview however you can update and
delete. If you want to insert new rows than either go for the
DetailsView or FormView control. These controls by default give you
leverage to insert new records.

Feb 22 '07 #2
On Feb 22, 2:43 pm, qasim.m...@gmail.com wrote:
On Feb 22, 2:36 pm, "rcoco" <nclau...@yahoo.cawrote:


Hi,
I'm working on a asp.net project with a datagrid. I want the user to
be adding data into Sql database using the datagrid. So I'm using a
ListBox to do this and edit update and delete. I placed listbox in
EditItemTemplate and label in ItemTemplate. but when I try now to edit
it does not bring the lisbox but i can read the grid with the sql
content. my code actually looks like this:
public void Edit_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
}
public void Cancel_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = -1;
BindDataGrid();
}
public void Update_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.ListBox st=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[5].FindControl("lbachobj**");
System.Web.UI.WebControls.ListBox st1=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[4].FindControl("lbobj");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into Object,AchievedObject where
@Object,@AchievedObject";
myCommand.Parameters.Add(new
SqlParameter("@AchievedObject",SqlDbType.Text));
myCommand.Parameters["@AchievedObject"].Value=st.SelectedValue;
myCommand.Parameters.Add(new SqlParameter("@Object",SqlDbType.Text));
myCommand.Parameters["@Object"].Value=st1.SelectedValue;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgid.EditItemIndex=-1;
BindDataGrid();
}
Thanks.

By data grid i assume you are talking about GridView. By default you
cannot insert new rows from within gridview however you can update and
delete. If you want to insert new rows than either go for the
DetailsView or FormView control. These controls by default give you
leverage to insert new records.- Hide quoted text -

- Show quoted text -
Thanks,
If I have gotten you write edit cannot insert a value into database.
So how can I solve this problem? How do I get Detailview or formview?
Thanks

Feb 22 '07 #3
Detailsview and Formview are standard web server controls in ASP.NET 2.0.
For example try
<asp:DetailsView runat="server" ID = "someID"></asp:DetailsView>

Which .net version are you using, 1.x, 2.0, ...?

--
Regards,
Kees de Winter
"rcoco" <nc******@yahoo.cawrote in message
news:11**********************@k78g2000cwa.googlegr oups.com...
On Feb 22, 2:43 pm, qasim.m...@gmail.com wrote:
On Feb 22, 2:36 pm, "rcoco" <nclau...@yahoo.cawrote:


Hi,
I'm working on a asp.net project with a datagrid. I want the user to
be adding data into Sql database using the datagrid. So I'm using a
ListBox to do this and edit update and delete. I placed listbox in
EditItemTemplate and label in ItemTemplate. but when I try now to edit
it does not bring the lisbox but i can read the grid with the sql
content. my code actually looks like this:
public void Edit_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
}
public void Cancel_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = -1;
BindDataGrid();
}
public void Update_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.ListBox st=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[5].FindControl("lbachobj*
*");
System.Web.UI.WebControls.ListBox st1=new
System.Web.UI.WebControls.ListBox();
st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[4].FindControl("lbobj");
SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into Object,AchievedObject where
@Object,@AchievedObject";
myCommand.Parameters.Add(new
SqlParameter("@AchievedObject",SqlDbType.Text));
myCommand.Parameters["@AchievedObject"].Value=st.SelectedValue;
myCommand.Parameters.Add(new SqlParameter("@Object",SqlDbType.Text));
myCommand.Parameters["@Object"].Value=st1.SelectedValue;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgid.EditItemIndex=-1;
BindDataGrid();
}
Thanks.

By data grid i assume you are talking about GridView. By default you
cannot insert new rows from within gridview however you can update and
delete. If you want to insert new rows than either go for the
DetailsView or FormView control. These controls by default give you
leverage to insert new records.- Hide quoted text -

- Show quoted text -
Thanks,
If I have gotten you write edit cannot insert a value into database.
So how can I solve this problem? How do I get Detailview or formview?
Thanks
Feb 23 '07 #4
Hi kees,

I'm using 2.0. I'm actually no longer using a listbox but in stead I'm
using a textbox. But now i'm facing another challenge. The user has to
insert new data in SQL using a datagrid. So I'm trying using a button.
The button should be able to get a new row so that user could enter
new records and I created another button that will enable the user to
save the records into SQL. My problem is to get the row ready to
insert data. could you be knowing how I could go about this?
Thanks

On Feb 23, 2:59 pm, "Kees de Winter" <nos...@nospam.orgwrote:
Detailsview and Formview are standard web server controls in ASP.NET 2.0.
For example try
<asp:DetailsView runat="server" ID = "someID"></asp:DetailsView>

Which .net version are you using, 1.x, 2.0, ...?

--
Regards,
Kees de Winter

"rcoco" <nclau...@yahoo.cawrote in message

news:11**********************@k78g2000cwa.googlegr oups.com...
On Feb 22, 2:43 pm, qasim.m...@gmail.com wrote:
On Feb 22, 2:36 pm, "rcoco" <nclau...@yahoo.cawrote:
Hi,
I'm working on a asp.net project with a datagrid. I want the user to
be adding data into Sql database using the datagrid. So I'm using a
ListBox to do this and edit update and delete. I placed listbox in
EditItemTemplate and label in ItemTemplate. but when I try now to edit
it does not bring the lisbox but i can read the grid with the sql
content. my code actually looks like this:
public void Edit_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
}
public void Cancel_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = -1;
BindDataGrid();
}
public void Update_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.ListBox st=new
System.Web.UI.WebControls.ListBox();

st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[5].FindControl("lbachobj**
*"); System.Web.UI.WebControls.ListBox st1=new
System.Web.UI.WebControls.ListBox();

st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[4].FindControl("lbobj");


SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into Object,AchievedObject where
@Object,@AchievedObject";
myCommand.Parameters.Add(new
SqlParameter("@AchievedObject",SqlDbType.Text));
myCommand.Parameters["@AchievedObject"].Value=st.SelectedValue;
myCommand.Parameters.Add(new SqlParameter("@Object",SqlDbType.Text));
myCommand.Parameters["@Object"].Value=st1.SelectedValue;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgid.EditItemIndex=-1;
BindDataGrid();
}
Thanks.
By data grid i assume you are talking about GridView. By default you
cannot insert new rows from within gridview however you can update and
delete. If you want to insert new rows than either go for the
DetailsView or FormView control. These controls by default give you
leverage to insert new records.- Hide quoted text -
- Show quoted text -

Thanks,
If I have gotten you write edit cannot insert a value into database.
So how can I solve this problem? How do I get Detailview or formview?
Thanks- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -

Feb 23 '07 #5
What kind of datagrid do you mean? Or do you mean GridView?

One way of doing it is to have a DetailsView control for the data-entry and
a GridView for showing a list of existing rows. Connect the DetailsView to
some datasource (for example Sql DataSource) and use the Property Editor to
set the DefaultMode property of the DetailsView control to "Insert". Then
create an InsertCommand in the SqlDataSource using the wizard. You will get
aspx code like this

<asp:DetailsView ID="DetailsView1" runat="server"
AutoGenerateRows="False" DataSourceID="SqlDataSource1"
DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="SomeID" HeaderText="SomeID"
InsertVisible="False"
ReadOnly="True" SortExpression="SomeID" />
<asp:BoundField DataField="SomeField1"
HeaderText="SomeField1" SortExpression="SomeField1" />
<asp:BoundField DataField="SomeField2"
HeaderText="SomeField2" SortExpression="SomeField2" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ your connectionstring %>"
SelectCommand="SELECT * FROM SomeTable"
InsertCommand="INSERT INTO SomeTable(somefield1, somefield2, )
VALUES (bla,bla,,)"></asp:SqlDataSource>

But there are lots of tutorials online for using the detailsview control
that explain this much better. Just search for 'detailsview insert'.

--
Regards,
Kees


"rcoco" <nc******@yahoo.cawrote in message
news:11*********************@p10g2000cwp.googlegro ups.com...
Hi kees,

I'm using 2.0. I'm actually no longer using a listbox but in stead I'm
using a textbox. But now i'm facing another challenge. The user has to
insert new data in SQL using a datagrid. So I'm trying using a button.
The button should be able to get a new row so that user could enter
new records and I created another button that will enable the user to
save the records into SQL. My problem is to get the row ready to
insert data. could you be knowing how I could go about this?
Thanks

On Feb 23, 2:59 pm, "Kees de Winter" <nos...@nospam.orgwrote:
Detailsview and Formview are standard web server controls in ASP.NET 2.0.
For example try
<asp:DetailsView runat="server" ID = "someID"></asp:DetailsView>

Which .net version are you using, 1.x, 2.0, ...?

--
Regards,
Kees de Winter

"rcoco" <nclau...@yahoo.cawrote in message

news:11**********************@k78g2000cwa.googlegr oups.com...
On Feb 22, 2:43 pm, qasim.m...@gmail.com wrote:
On Feb 22, 2:36 pm, "rcoco" <nclau...@yahoo.cawrote:
Hi,
I'm working on a asp.net project with a datagrid. I want the user to
be adding data into Sql database using the datagrid. So I'm using a
ListBox to do this and edit update and delete. I placed listbox in
EditItemTemplate and label in ItemTemplate. but when I try now to edit
it does not bring the lisbox but i can read the grid with the sql
content. my code actually looks like this:
public void Edit_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = e.Item.ItemIndex;
BindDataGrid();
}
public void Cancel_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dgid.EditItemIndex = -1;
BindDataGrid();
}
public void Update_dgid(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
System.Web.UI.WebControls.ListBox st=new
System.Web.UI.WebControls.ListBox();

st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[5].FindControl("lbachobj*
*
*"); System.Web.UI.WebControls.ListBox st1=new
System.Web.UI.WebControls.ListBox();

st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[4].FindControl("lbobj");
>

SqlCommand myCommand=new SqlCommand();
myCommand.Connection=con;
myCommand.CommandText="insert into Object,AchievedObject where
@Object,@AchievedObject";
myCommand.Parameters.Add(new
SqlParameter("@AchievedObject",SqlDbType.Text));
myCommand.Parameters["@AchievedObject"].Value=st.SelectedValue;
myCommand.Parameters.Add(new SqlParameter("@Object",SqlDbType.Text));
myCommand.Parameters["@Object"].Value=st1.SelectedValue;
con.Open();
myCommand.ExecuteNonQuery();
con.Close();
dgid.EditItemIndex=-1;
BindDataGrid();
}
Thanks.
By data grid i assume you are talking about GridView. By default you
cannot insert new rows from within gridview however you can update and
delete. If you want to insert new rows than either go for the
DetailsView or FormView control. These controls by default give you
leverage to insert new records.- Hide quoted text -
- Show quoted text -

Thanks,
If I have gotten you write edit cannot insert a value into database.
So how can I solve this problem? How do I get Detailview or formview?
Thanks- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -


Feb 23 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andla Rand | last post by:
Hi, Could you help me to understand how datagrid works. I'm trying to make a datagrid editable. Now most of the tutorials I read says that i should turn the Enable ViewState off. Why is that? ...
4
by: Stephan Bour | last post by:
Hi, I have a datagrid databound to a SQL query. I'd like to allow editing of some columns but not all. Is there a way to turn off the conversion of the datagrid cells to textboxes for some columns...
0
by: DaveR | last post by:
I have a webform with a two-column datagrid based on an Arraylist. The Arraylist draws the data for the two columns from two different tables in an SQL database. The data is displayed in datagrid...
2
by: zambizzi | last post by:
....I can't seem to get my hands on a control I'm loading in an editable datagrid. Here's my datagrid control: <asp:datagrid id="GLRulesGrid" runat="server" autogeneratecolumns="False"...
6
by: Richard L Rosenheim | last post by:
I'm sure it can be done, I haven't been able to find the right article yet. I want to be able to filter the records that the datagrid displays, but still have an editable datagrid. That is, I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.