473,406 Members | 2,549 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,406 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 2201
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.