Click here to Skip to main content
15,888,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i have a problem where i want to bind data that just entered by user (for instance from dropdown and textbox) into gridview so that they can review it.then if they want to delete they can delete or if satisfy then can proceed to submit the data.

i only thought gridview because i used to it.maybe you guys have another idea or method to bind latest data that enter by user.i already tried to bind, but it goes bind all the table.so the previous data also displayed.i just want the latest data that entered by this user only.

thanks in advance
musiw.
Posted
Comments
AshishChaudha 16-Jul-12 1:24am    
Could you show us the code, so, It will be great to help you better.
musiw 16-Jul-12 3:31am    
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource2">
<columns>
<asp:BoundField DataField="nama_barang" HeaderText="nama_barang"
SortExpression="nama_barang" />
<asp:BoundField DataField="bilangan" HeaderText="bilangan"
SortExpression="bilangan" />
<asp:BoundField DataField="stock_last" HeaderText="stock_last"
SortExpression="stock_last" />


<br />

<br />

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:connectionString %>"
SelectCommand="SELECT [nama_barang], [bilangan], [stock_last] FROM [approval]">



protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection cn0 = new SqlConnection(connectionString);
cn0.Open();


int last = int.Parse(Label3.Text);
int req = int.Parse(TextBox7.Text);
int kuantiti = last - req;


string s = "update stocks set stock_left = @stock_left where id_ = '" + ddl1.SelectedIndex + "'";
SqlCommand cd = new SqlCommand(s, cn0);

cd.Parameters.Add("@stock_left", SqlDbType.Int).Value = kuantiti;


string l = "insert into approval (item, quantity, stock_last) values (@item, @quantity, @stock_last)";
SqlCommand c = new SqlCommand(l, cn0);
c.Parameters.Add("@item", SqlDbType.VarChar).Value = ddl1.SelectedItem.Text.Trim();
c.Parameters.Add("@quantity", SqlDbType.Int).Value = TextBox7.Text.Trim();
c.Parameters.Add("@stock_last", SqlDbType.Int).Value = kuantiti;

cd.ExecuteNonQuery();
c.ExecuteNonQuery();
}

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{

SqlConnection cn = new SqlConnection(connectionString);
cn.Open();
string sql = "select stock_left from stocks where nama_barang = '"+ ddl1.SelectedItem.Text +"' ";
SqlCommand c = new SqlCommand(sql, cn);
SqlDataReader dr = c.ExecuteReader();
dr.Read();

if (Convert.ToInt32(dr[0]) > 0)
{
Label3.Text = Convert.ToString(dr[0]);
}
else
{
Label3.Text = "No stock!";
Label3.ForeColor = System.Drawing.Color.Red;
}





}
protected void Button5_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
}

1 solution

Bind your Gridview again after submitting records.

C#
GridView1.Datasource=ds;
GridView1.Databind();


Thanks
Ashish
 
Share this answer
 
Comments
musiw 17-Jul-12 21:39pm    
cannot.i already tried.i also try select @@identity, also cannot. it display all the data from table.i just want the data that last inserted.lets say user insert 2 records into table, then i want gridview display 2 records.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900