DataGridGiew中每行都绑定了动态添加的按钮控件,我想单击按钮能获取到行号,
按钮单击时,这行并没有被触发,我怎样能获取到行号?
或者单击按钮时触发这行也行。我主要是想获取到这行数据。
怎样能够实现?注:按钮是绑定添加到DataGridGiew中的。还有DataGridGiew中DataGridViewComboBoxColumn这列,我可以只更改这个控件的宽度,而不改变列的宽度吗?
按钮单击时,这行并没有被触发,我怎样能获取到行号?
或者单击按钮时触发这行也行。我主要是想获取到这行数据。
怎样能够实现?注:按钮是绑定添加到DataGridGiew中的。还有DataGridGiew中DataGridViewComboBoxColumn这列,我可以只更改这个控件的宽度,而不改变列的宽度吗?
解决方案 »
- 发现一个bug textbox对size限制没有效果
- 屏幕截取并发送问题。。
- 新闻发布系统(增删改页面)
- 关于listbox大小的运算
- C# 2.0实现了泛型技术,泛型到底是怎么一回事?他是编译时进行类型设置,还是运行时?我能不能用一个非泛型类继承一个泛型类?
- 使用sqlhelper类时遇到的问题,请各位帮忙看看怎么回事
- 高分请教高手!c# ftp unix 服务器问题
- c# 如何使用sql的新功能 MERGESQL
- (c#)如何让form2不跟随form1最小化
- 如何获得input,checkbox的值?
- vs2008添加数据库连接失败,IvsDataConnectionDialog未能初始化
- 万能的csdn 哪位同学给我.NET Windows编程系列课程 源代码
<asp:GridView ID="grvzcan" DataKeyNames="zcid" HeaderStyle-CssClass="grvheader" runat="server" BorderColor="#3387D7" BorderWidth="1px"
Width="976px" AutoGenerateColumns="False" CssClass="grvdanju" OnRowDeleting="GridView1_RowDeleting" OnRowDataBound="grvzcan_RowDataBound">
<Columns>
<asp:BoundField DataField="zcid" HeaderText="单据编号" />
<asp:BoundField DataField="did" HeaderText="主单据编号" />
<asp:TemplateField HeaderText="单据名称">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("zcan") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("zcname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="znumber" HeaderText="数量" />
<asp:BoundField DataField="zsums" HeaderText="金额" />
<asp:BoundField DataField="zbeizhu" HeaderText="资产描述" />
<asp:CommandField HeaderText="删除" ShowDeleteButton="True" />
<asp:TemplateField HeaderText="修改">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="libtnxuanzhe" runat="server" Text="修改" CommandName='<%#Eval("zcid")%>' OnCommand="libtnxuanzhe_Command">修改</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<HeaderStyle CssClass="grvheader" />
</asp:GridView>
后台代码: protected void grvzcan_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//加光棒效果
e.Row.Attributes.Add("onmouseover", "current=this.style.backgroundColor;this.style.backgroundColor='#CCFFFF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=current"); //添加点击行事件
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackClientHyperlink(e.Row.Cells[0].FindControl("libtnxuanzhe"), ""));
e.Row.Attributes.CssStyle.Add("cursor", "hand");
}
} //点击行选择按钮或行时将对应的信息绑定到文本框中显示。
protected void libtnxuanzhe_Command(object sender, CommandEventArgs e)
{
int zcid = int.Parse(e.CommandName);
Session["zcidse"] = zcid;
zchan zcan = zchanmaager.getzchanByzcid(zcid);
this.txtzcdaim.Text=zcan.Cpin.Cpid.ToString();
this.txtcname.Text=zcan.Cpin.Cname;
this.txtcdanwei.Text = zcan.Cpin.Cdanwei;
this.txtnumber.Text = zcan.Znumber.ToString();
this.txtcdanjia.Text = zcan.Cpin.Cdanjia.ToString();
this.txtnumber.Text = zcan.Znumber.ToString();
this.txtcnumber.Text = zcan.Cpin.Cnumber.ToString();
this.txtzsums.Text = zcan.Zsums.ToString();
this.txtzbeizhu.Text = zcan.Zbeizhu; }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
e.RowIndex //行号!
}
{
if (e.ColumnIndex == this.dataGridView1.Columns["column名称"].Index)
{
DataGridViewButtonCell vCell = (DataGridViewButtonCell)dataGridView1.CurrentCell;
if (vCell.Tag == null)
{
//index
int i = e.ColumnIndex;
//修改数据
vCell.Value = "xxxx";
vCell.Tag = true;
return;
}
}
}
dataGridView1.Columns[0].MinimumWidth = xx;
dataGridView1.Rows[0].MinimumHeight = xx;