Sie sind auf Seite 1von 2

<asp:GridView ID="gvImages" runat="server" AutoGenerateColumns="false"

OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField ItemStyle-Width="150px" DataField="Id" HeaderText="id" />
<asp:BoundField ItemStyle-Width="150px" DataField="fisrtname"
HeaderText="firstname" />
<asp:BoundField ItemStyle-Width="150px" DataField="lastname"
HeaderText="lastname" />
<asp:BoundField ItemStyle-Width="150px" DataField="designation"
HeaderText="designation" />
<asp:BoundField ItemStyle-Width="150px" DataField="address"
HeaderText="address" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

<%-- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"


OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Image Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" />
</ItemTemplate>

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)


{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated
Security=True;User Instance=True");
int id =
Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("delete from tbl_data where id =@id", con);

cmd.Parameters.AddWithValue("id", id);
int i = cmd.ExecuteNonQuery();
con.Close();
refreshdata();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
refreshdata();
}

protected void GridView1_RowCancelingEdit(object sender,


GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
refreshdata();
}

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

{
SqlConnection con = new SqlConnection(@"Data
Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated
Security=True;User Instance=True");

TextBox txtname = GridView1.Rows[e.RowIndex].FindControl("TextBox1") as


TextBox;
TextBox txtcity = GridView1.Rows[e.RowIndex].FindControl("TextBox2") as
TextBox;
int id =
Convert.ToInt16(GridView1.DataKeys[e.RowIndex].Values["id"].ToString());
con.Open();
SqlCommand cmd = new SqlCommand("sp_updatedata", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("name", txtname.Text);
cmd.Parameters.AddWithValue("city", txtcity.Text);
cmd.Parameters.AddWithValue("id", id);

int i = cmd.ExecuteNonQuery();
con.Close();
GridView1.EditIndex = -1;
refreshdata();

}
</asp:TemplateField>
</Columns>
</asp:GridView>--%>