ASP.NET GridView单元格编辑备选方案
是否可以编辑和更新GridView单元格而不使用 和/或 和/或 和/或 SqlDataSource 注意:我只想在后台使用C代码,并使用SqlConnection、SqlCommand、ExecuteXXX等 注意:请为我提供编解码器和aspx或包含代码的web链接。在gridview标记中使用onrowediting和onrowUpdate。。。 大概是这样的:ASP.NET GridView单元格编辑备选方案,asp.net,data-binding,Asp.net,Data Binding,是否可以编辑和更新GridView单元格而不使用 和/或 和/或 和/或 SqlDataSource 注意:我只想在后台使用C代码,并使用SqlConnection、SqlCommand、ExecuteXXX等 注意:请为我提供编解码器和aspx或包含代码的web链接。在gridview标记中使用onrowediting和onrowUpdate。。。 大概是这样的: <asp:GridView ID="GridView1" runat="server" CellPadding="4"
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AllowPaging="true" AllowSorting="true" PageSize="5" DataKeyNames="Id"
onpageindexchanging="GridView1_PageIndexChanging"
AutoGenerateEditButton="true" AutoGenerateDeleteButton="true"
onsorting="GridView1_Sorting" onrowediting="GridView1_RowEditing">
通常,使用Sqlcommand和Sqlconnection的代码类似于:
SqlConnection con;
SqlCommand cmd;
DataSet ds;
SqlDataAdapter da;
protected DataSet FillDataSet()
{
string source = "Database=GridTest;Server=Localhost;Trusted_Connection=yes";
con = new SqlConnection(source);
cmd = new SqlCommand("proc_mygrid", con);
ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
return ds;
}
希望这有帮助。一个可能的解决方案可能是管理gridview的RowDataBound事件,并设置如下值
e.Row.Cells(i).Text = value
我仍然不明白你为什么要反对asp.net,但是你可以使用ObjectDataSource做你想做的事情。ObjectDataSource控件使用反射调用业务对象的方法来选择、更新、插入和删除数据。设置ObjectDataSource控件的TypeName属性以指定用作源对象的类的名称 使用ObjectDataSource resume执行以下操作: 声明: 要在代码隐藏中创建方法,请执行以下操作: 要配置GridView并感到高兴,请执行以下操作: 下面我提供了一些可能对您有所帮助的链接:
我还需要消除SqlDataSource并使用Winforms样式的SqlCommand、SqlCennection等,因为我来自Winforms后台。
e.Row.Cells(i).Text = value
<asp:objectdatasource
runat="server"
id="ObjectDataSource1"
typename="EmployeeLogic"
selectmethod="GetAllEmployees"
updatemethod="UpdateEmployeeInfo"
dataobjecttypename="NorthwindEmployee" />
public List<NorthwindEmployee>GetAllEmployees()
{
//your code here
}
public void UpdateEmployeeInfo(NorthwindEmployee emp) {
//your code here
}