gridview有没有办法一点编辑就马上取出当前行某列的值.
(以前用的办法是先点编辑,然后点更新,更新事件里写上
((textbox)this.gridview1.rows[e.rowindex].cells[0].controls[0]).text.tostring()的办法来取, 能不能直接点编辑就可以取出来呢.)
(以前用的办法是先点编辑,然后点更新,更新事件里写上
((textbox)this.gridview1.rows[e.rowindex].cells[0].controls[0]).text.tostring()的办法来取, 能不能直接点编辑就可以取出来呢.)
模板列哦~
<asp:LinkButton ID="lb" runat="server" CommandName="editrow" Text="编辑" CommandArgument=' <%# Container.DataItemIndex %>'/>
cs文件代码:
protected void gv_sata_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "editrow")
{
int iIndex = Convert.ToInt16(e.CommandArgument);
GridViewRow gvr = gv_User.Rows[iIndex];
string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦
}
}
这个问题貌似我昨天还回答过。
新手,互相帮助!
这句是起什么作用的呢
{
if (e.CommandName == "editrow")
{
int iIndex = Convert.ToInt16(e.CommandArgument);
GridViewRow gvr = gv_User.Rows[iIndex];
string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦
}
}
我照搬以上代码,结果发现点编辑按纽的时候不起作用,我改成如下代码
protected void gv_sata_RowCommand(object sender, GridViewCommandEventArgs e)
{
int iIndex = Convert.ToInt16(e.CommandArgument);
GridViewRow gvr = gv_User.Rows[iIndex];
string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦
}
就没有问题,不知道那个IF加上去干嘛用,加上了,反而不灵了.
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
bind();
}
BorderStyle="None" Width="100%" onrowdeleting="GridView1_RowDeleting"
onrowediting="GridView1_RowEditing"
onselectedindexchanging="GridView1_SelectedIndexChanging"
BackColor="White" BorderColor="#CCCCCC" BorderWidth="1px" CellPadding="3"
DataKeyNames="isosid" onrowupdating="GridView1_RowUpdating"
onrowcommand="GridView1_RowCommand">
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<Columns>
<asp:BoundField DataField="isosid" HeaderText="ID" />
<asp:BoundField DataField="规格型号" HeaderText="规格型号" />
<asp:BoundField DataField="数量" HeaderText="数量" />
<asp:BoundField DataField="材质颜色" HeaderText="材质颜色" />
<asp:BoundField DataField="客户型号" HeaderText="客户型号" />
<asp:BoundField DataField="包装要求" HeaderText="包装要求" />
<asp:BoundField DataField="连接器类型" HeaderText="连接器类型" />
<asp:BoundField DataField="完结" HeaderText="完结" />
<asp:BoundField DataField="完结时间" HeaderText="完结时间" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowSelectButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
以上是我gridview1的代码,问题是gridview1上面明明就有编辑,选择,删除,等三个按纽,为什么在代码上看不到呢
<asp:CommandField ShowSelectButton="True" />
<asp:CommandField ShowDeleteButton="True" />
这样的话直接row_editing , row_updating事件就可以了,不用row_command了
<asp:CommandField ShowSelectButton="True" />
<asp:CommandField ShowDeleteButton="True" /> 这3行换成模版列试试。<asp:TemplateField HeaderText="编辑" ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lb" runat="server" CommandName="editrow" Text="编辑" CommandArgument=' <%# Container.DataItemIndex %>'/>
</ItemTemplate>
</asp:TemplateField>然后后台代码:
cs文件代码: protected void gv_sata_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "editrow")
{
int iIndex = Convert.ToInt16(e.CommandArgument);
GridViewRow gvr = gv_User.Rows[iIndex];
string text = gvr.Cells[0].Text; //根据你要取值的列改索引值哦
}
} 注意红色部分是对应的。