Editable datagrid

R

rcoco

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.
 
Q

qasim.manu

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.
 
R

rcoco

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
 
K

Kees de Winter

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


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
 
R

rcoco

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

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



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 -
 
K

Kees de Winter

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




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

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


st=(System.Web.UI.WebControls.ListBox)e.Item.Cells[5].FindControl("lbachobj­
­
­");> > System.Web.UI.WebControls.ListBox st1=newst=(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 -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top