网格视图问题 [英] grid view question

查看:80
本文介绍了网格视图问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给我代码或想法

give me the code or Idea for

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

推荐答案

只要您想更新网格视图的行,就使用此事件.
请阅读以下链接以获取更多信息.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx [
this event is used whenever you wanna update a Grid View''s Row.
Please read the below link for more Info.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowupdating.aspx[^]


您可以使用此事件将行数据绑定到网格.因此,如果您需要在数据绑定之前更改行的颜色或在行级别进行某些操作,例如向按钮单击添加警报(单元格中任一单元中存在按钮)
You can use this event to trap row-wise data binding to grid. Thus, if you need to change color of row or some manipulation at row level before databound, like adding an alert to button click (button present in any one of the cell)
//Something similar to this
protected void Gridview_RowDatabound(object sender, DataGridItemEventArgs e)
{
     Button btn = (Button)e.Row.FindControl("myDeleteButton");
     if (btn != null)
     {
         // you got btn object here. Do any manipulation desired.
         // btn.Text = "Hi There"+someRandomNumber;
         // btn.OnClientClick = "CallMeWhenDeleteIsPressed";
     }
}


public void Grid()    {        
            SqlConnection con = new SqlConnection("server=. ; integrated security=sspi; database = Ram");      
            con.Open();       
            SqlDataAdapter da = new SqlDataAdapter("select *  from Ram ", con);       
               
            DataSet ds= new DataSet();       
           da.Fill(ds, "Ram");       
           GridView1.DataSource = ds;       
           GridView1.DataBind();       
           ListBox1.DataSource = ds;      
           ListBox1.DataTextField = ds.Tables[0].Columns[0].ToString();              
           ListBox1.DataBind();       
           con.Close();   
    }


protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)    {       
                           
               Button  lb = new Button();       
               TextBox txt1 = new TextBox();       
               txt1 = (TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0];      
               string str1 = Convert.ToString(txt1.Text);          
               TextBox txt4 = new TextBox();       
               txt4 = (TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0];       
               string str4 = Convert.ToString(txt4.Text);              
               TextBox txt2 = new TextBox();       
               txt2 = (TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0];       
               string str2 = Convert.ToString(txt2.Text);       
               TextBox txt3 = new TextBox();       
               txt3 = (TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0];      
               string str3 = Convert.ToString(txt3.Text);              
               SqlConnection con = new SqlConnection("server=. ; integrated security=sspi; database = Ram");      
               con.Open();       
              SqlCommand com = new SqlCommand("update Ram set NAME=@NAME,Fname=@age,address =@address where id=@lname", con);       
              com.Parameters.AddWithValue("@lname", str1);       
              com.Parameters.AddWithValue("@age", str2);       
              com.Parameters.AddWithValue("@address", str3);       
              com.Parameters.AddWithValue("@NAME", str4);       
              com.ExecuteNonQuery();       
              Response.Write("successfully updated");      
              GridView1.EditIndex = -1;       
              Grid();                               
   }


这篇关于网格视图问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆