Re: Editable datagrid

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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...@xxxxxxxxxx> wrote:
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...@xxxxxxxx> wrote in message

news:1172149707.315054.326070@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Feb 22, 2:43 pm, qasim.m...@xxxxxxxxx wrote:



On Feb 22, 2:36 pm, "rcoco" <nclau...@xxxxxxxx> wrote:

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 -


.


Quantcast