从gridView中的RowCommand调用RowEdit事件 [英] Calling RowEdit Event from RowCommand In gridView

查看:64
本文介绍了从gridView中的RowCommand调用RowEdit事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从RowCommand调用RowEdit

i need to call RowEdit from RowCommand

<asp:TemplateField HeaderText="BOX_NO" HeaderStyle-Width="12%">
                           <ItemTemplate>
                               <asp:LinkButton ID="lbtn_BOX_NO" runat="server" CommandName="edit"  ></asp:LinkButton>

                           </ItemTemplate>
                           <EditItemTemplate>
                               <asp:TextBox ID="txt_BOX_NO" Height="12px"  runat="server" Text='<%# Bind("BOX_NO") %>'></asp:TextBox>
                           </EditItemTemplate>
                           <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
                           <ItemStyle HorizontalAlign="Left"></ItemStyle>
                       </asp:TemplateField>


protected void grd_device_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if(e.CommandName=="edit")
           {
        grd_device_RowEditing(sender,(GridViewEditEventArgs)((e)));
          }
       }
       protected void grd_device_RowEditing(object sender, GridViewEditEventArgs e)
       {
           grd_device.EditIndex = e.NewEditIndex;
           LoadGrid();
       }




通过我的IT错误
CS0030:无法将类型"System.Web.UI.WebControls.GridViewCommandEventArgs"转换为"System.Web.UI.WebControls.GridViewEditEventArgs"




IT through me the error
CS0030: Cannot convert type ''System.Web.UI.WebControls.GridViewCommandEventArgs'' to ''System.Web.UI.WebControls.GridViewEditEventArgs''

推荐答案

您的GridView设计将如下所示:-
your GridView design would be like this:-
<asp:gridview id="gridview" runat="server" autogeneratecolumns="false" datakeyname="User_Id" OnRowEditing="gridvew_RowEditing" onrowcommand="gridview_OnRowCommand" >
<columns>
 <asp:templatefield>
  <itemtemplate>
    <asp:linkbutton id="lnkEdit" runat="server" commandname="Edit" />
  </itemtemplate>
  <edititemtemplate>
    <aps:linkbutton id="lnkUpdate"  runat="server" commandname="Update" />
  </edititemtemplate>
</asp:templatefield>
<asp:templatefield headertext="YOur Header">
 <itemtemplate>
  <asp:label id="lblName" runat="server" text='<%# Eval("User_Name")%>' />
 </itemtemplate>
<edititemtemplate>
 <asp:textbox id="txtUName" runat="server" text='<%# Eval("User_Name")%>' />
</edititemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>



现在OnRowCommand:-



Now OnRowCommand:-

protected void gridview_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
 if(e.CommandName=="Update")
 {
   //find your textbox
  GridViewRow gvr = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
  TextBox txtname = (TextBox)gvr.FindControl("txtUName");
  string name = txtname.Text;
 //write your code.
 }
}



OnRowEditing ..



OnRowEditing..

protected void gridvew_RowEditing(object sender, GridViewEditEventArgs e)
   {
       gridview.EditIndex = e.NewEditIndex;
       BindList();
   }



希望你明白了.



hope you got it.



尝试将命令名称"edit"更改为"Edit".它将自动触发GridView的RowEditing evnet.您需要处理该事件.
Hi,
Try changing your Command name "edit" to "Edit". It will autometically fire RowEditing evnet of GridView. You need to handle that event.
<asp:templatefield headertext="BOX_NO" headerstyle-width="12%" xmlns:asp="#unknown">
    <itemtemplate>
        <asp:linkbutton id="lbtn_BOX_NO" runat="server" commandname="Edit"> 
        </asp:linkbutton>     
    </itemtemplate>
    <edititemtemplate>
        <asp:textbox id="txt_BOX_NO" height="12px" runat="server" text="<%# Bind("BOX_NO") %>">
        </asp:textbox>
    </edititemtemplate>
    <HeaderStyle HorizontalAlign="Left"></HeaderStyle>
    <itemstyle horizontalalign="Left"></itemstyle>
</asp:templatefield>



处理RowEditig evnet:



Handling RowEditig evnet:

protected void gvEmpDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
    gvEmpDetails.EditIndex = e.NewEditIndex;
    fnBindEmpDetails();
}





--Amit





--Amit


这篇关于从gridView中的RowCommand调用RowEdit事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆