gridview 手动绑定问题
gridview手动绑定后如何修改headertext,进行增删改,排序分布。最好能给个实例看看~直接指定gridview.columns[i].headertext="...
gridview 手动绑定后如何修改headertext,进行增删改,排序分布。最好能给个实例看看~直接指定gridview.columns[i].headertext="";实现不了
SqlConnection con1 = SQL.connection();
SqlCommand cmd1 = new SqlCommand("gridview", con1);
cmd1.Parameters.AddWithValue("@fathername", "根列表");
cmd1.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada1 = new SqlDataAdapter();
ada1.SelectCommand = cmd1;
DataSet ds1 = new DataSet();
ada1.Fill(ds1, "aa");
//GridView1.DataSourceID = "";
GridView2.DataSource = ds1.Tables["aa"].DefaultView;
GridView2.DataBind();
gridview只指定了个ID,没做任何其它设置 展开
SqlConnection con1 = SQL.connection();
SqlCommand cmd1 = new SqlCommand("gridview", con1);
cmd1.Parameters.AddWithValue("@fathername", "根列表");
cmd1.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ada1 = new SqlDataAdapter();
ada1.SelectCommand = cmd1;
DataSet ds1 = new DataSet();
ada1.Fill(ds1, "aa");
//GridView1.DataSourceID = "";
GridView2.DataSource = ds1.Tables["aa"].DefaultView;
GridView2.DataBind();
gridview只指定了个ID,没做任何其它设置 展开
2个回答
网易云信
2023-12-06 广告
2023-12-06 广告
信令SDK是一种软件开发工具包,旨在帮助开发者在应用程序中实现信令协议的通信功能。它主要提供了一系列函数、协议和工具,用于处理信令消息的生成、解析、传输和存储等操作。通过使用信令SDK,开发者可以更快速、便捷地实现信令通信功能,提高应用程序...
点击进入详情页
本回答由网易云信提供
展开全部
首先设置gridview的DataKeyNames属性绑定表的主键列
然后把GridView的AutoGenerateColumns属性设置为true
自动生成有好多值是取不到得
添加模版列并绑定值
<asp:TemplateField HeaderText="链接网址">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Url_frli") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtUrl" runat="server" Text='<%# Bind("Url_frli") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<EditItemTemplate>是编辑用的里面的TextBox 的ID名字要取好,Text='<%# Bind("Url_frli") %>'绑定表列的列名
</asp:TemplateField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True" >
</asp:CommandField >
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" OnClientClick="return confirm('确定删除吗?')"
CommandName="Delete" Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
后台代码***********************************
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//获取编辑行的索引
GridView1.EditIndex = e.NewEditIndex;
Bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新数据
int id =int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
CustomItem citem = CustomItemManager.GetCustomItem(id);
citem.ItemName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtItem")).Text;
CustomItemManager.SaveCustomItem(citem);
string url = Request.Url.ToString();
Response.Redirect(url);
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//取消编辑
GridView1.EditIndex = -1;
Bind();
}
删除
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//获取选中行的绑定的ID,将ID作为参数传给删除方法
string Serial = GridView1.DataKeys[e.RowIndex].Value.ToString();
CustomItemManager.DeleteCustomItems(int.Parse(Serial)))
}
然后把GridView的AutoGenerateColumns属性设置为true
自动生成有好多值是取不到得
添加模版列并绑定值
<asp:TemplateField HeaderText="链接网址">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Url_frli") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtUrl" runat="server" Text='<%# Bind("Url_frli") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<EditItemTemplate>是编辑用的里面的TextBox 的ID名字要取好,Text='<%# Bind("Url_frli") %>'绑定表列的列名
</asp:TemplateField>
<asp:CommandField HeaderText="编辑" ShowEditButton="True" >
</asp:CommandField >
<asp:TemplateField HeaderText="删除" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" OnClientClick="return confirm('确定删除吗?')"
CommandName="Delete" Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
后台代码***********************************
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//获取编辑行的索引
GridView1.EditIndex = e.NewEditIndex;
Bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//更新数据
int id =int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
CustomItem citem = CustomItemManager.GetCustomItem(id);
citem.ItemName = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtItem")).Text;
CustomItemManager.SaveCustomItem(citem);
string url = Request.Url.ToString();
Response.Redirect(url);
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
//取消编辑
GridView1.EditIndex = -1;
Bind();
}
删除
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//获取选中行的绑定的ID,将ID作为参数传给删除方法
string Serial = GridView1.DataKeys[e.RowIndex].Value.ToString();
CustomItemManager.DeleteCustomItems(int.Parse(Serial)))
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询