gridview显示的是设备的列表,每一行的下面是该设备的配件信息。设备的行前面有个按钮,可以展开或者隐藏配件行。这些显示都没有问题,问题出在点击删除按钮的时候,代码是这样写的
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" CommandName="deletedevice" ImageUrl="~/images/delete.gif"
OnClientClick="return confirm('确定要删除吗?');" CommandArgument='<%#Eval("code") %>'/>
</ItemTemplate>
</asp:TemplateField>protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//隐藏信息
Table table = e.Row.Parent as Table;
if (table != null)
{
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal); row.Style.Add("display", "none");
row.ID = DataBinder.Eval(e.Row.DataItem, "code").ToString(); TableCell cell = new TableCell();
LiteralControl ctl = new LiteralControl(); DataSet dspart = dbm.SelectPart(devicecode);
for (int i = 0; i < dspart.Tables[0].Rows.Count; i++)
{
ctl.Text += dspart.Tables[0].Rows[i][1].ToString();
ctl.Text += " : ";
ctl.Text += dspart.Tables[0].Rows[i][2].ToString() + "<br />";
}
cell.Controls.Add(ctl); cell.ColumnSpan = 4;
cell.Style.Add("padding-left", "50px"); row.Cells.Add(cell);
table.Rows.Add(row);
}
}
}
protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "deletedevice")
{
ImageButton imgdel = (ImageButton)e.CommandSource;
string code = imgdel.CommandArgument;
dbm.DeleteDevice(code);
BindGrid();
}
}
在Grid1_RowCommand函数中,参数的值很奇怪,第一个删除按钮的参数正确,第二个按钮的参数为空,第三个按钮的是第二个按钮的参数,第四个按钮的参数为空,以此类推。我觉得可能是因为隔一行被隐藏了。为什么会这样啊?怎样才能正确读取按钮的参数值?
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:ImageButton ID="imgDelete" runat="server" CommandName="deletedevice" ImageUrl="~/images/delete.gif"
OnClientClick="return confirm('确定要删除吗?');" CommandArgument='<%#Eval("code") %>'/>
</ItemTemplate>
</asp:TemplateField>protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//隐藏信息
Table table = e.Row.Parent as Table;
if (table != null)
{
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal); row.Style.Add("display", "none");
row.ID = DataBinder.Eval(e.Row.DataItem, "code").ToString(); TableCell cell = new TableCell();
LiteralControl ctl = new LiteralControl(); DataSet dspart = dbm.SelectPart(devicecode);
for (int i = 0; i < dspart.Tables[0].Rows.Count; i++)
{
ctl.Text += dspart.Tables[0].Rows[i][1].ToString();
ctl.Text += " : ";
ctl.Text += dspart.Tables[0].Rows[i][2].ToString() + "<br />";
}
cell.Controls.Add(ctl); cell.ColumnSpan = 4;
cell.Style.Add("padding-left", "50px"); row.Cells.Add(cell);
table.Rows.Add(row);
}
}
}
protected void Grid1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "deletedevice")
{
ImageButton imgdel = (ImageButton)e.CommandSource;
string code = imgdel.CommandArgument;
dbm.DeleteDevice(code);
BindGrid();
}
}
在Grid1_RowCommand函数中,参数的值很奇怪,第一个删除按钮的参数正确,第二个按钮的参数为空,第三个按钮的是第二个按钮的参数,第四个按钮的参数为空,以此类推。我觉得可能是因为隔一行被隐藏了。为什么会这样啊?怎样才能正确读取按钮的参数值?
解决方案 »
- jquery +autocomplete 的问题 。。
- private interal的应用级别 在什么情况下用
- 怎么在asp.net 中使用 winform 的 TabControl 控件
- label 分页
- 旧话重提,如何在Command_Click前用JS检测检测是否为空?为空,则不执行。
- GridView控件数据为空时,不能正常显示的问题
- 刚学asp.net,DataGrid的属性生成器异常
- e.CommandName的问题
- 关于Gridview控件在编辑状态时如何限制输入的字符长度
- 更新数据库的某一个字段怎么做?我的代码如下,可是没有用?谢谢!
- 脚本执行问题,请高手回答,
- (ajax net 如同注册) 返回值的赋值怎么处理
ImageButton imgdel = this.GridView1.Rows[_rowIndex].Cells[0].FindControl("imgDelete");
string code = imgdel.CommandArgument;
dbm.DeleteDevice(code);
BindGrid();
1.将某列转换为模板列,隐藏--即该列visibled=false;
2.取的该列的值,用FindControl取!!
点击模板列的按钮时,第一行e.CommandArgument可以取得,第二行e.CommandArgument=""