本文介绍了标签未在gridview中显示row_updating事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在vb.net中开发应用程序
aspx:

i am developing application in vb.net
aspx:

<div>
<asp:gridview runat="server" id="grid1">
<asp:bound field......./>--empid
<asp:bound field......./>--empname
<asp:bound field......./>--deptname

</asp:gridview>
<asp:lable runat="server" id="lblerror" />
</div>



axpx.cs:


我内部有一个网格,我有3个绑定的列
1.empid
2.empno(可编辑)
3.empname

empno应该只允许20,21,如果我输入的不是20,21,那么我想显示错误消息
将x暗淡为boolean = false

因此在行更新事件中



axpx.cs:


i have a grid inside i have 3 bound columns
1.empid
2.empno(editable)
3.empname

empno should allow only 20,21 ,if i enter not 20,21 then i want to show error message
dim x as boolean=false

so in row updating event

public sub gridview1_rowupdatingevent(s.........,e....)handles .......
{
if(empno=20 OR empno=21) then

//implementation
x=true
END IF
if(x=false)then

lblmessage.text="please enter 20,21."
END IF

}


如果我在ROW_UPDATING事件中使用,标签将在PAGE_LOAD事件中显示,但控制相同,这是行不通的.您能指导我吗?

问题是lblmessage没有在运行时显示文本.请帮助我


LABEL IS DISPLAYING AT PAGE_LOAD EVENT BUT SAME CONTROL IF I USE INSIDE ROW_UPDATING EVENT IT IS NOT WORKING. CAN YOU PLEASE GUIDE ME.

problem is lblmessage is was not displaying the text in runtime. please help me

推荐答案

<div>

    <asp:GridView runat="server" ID="gridEmp" DataKeyNames="empid" AutoGenerateColumns="false" OnRowEditing="GridviewEmpEditing" OnRowUpdating="GridviewEmpUpdating" OnRowCancelingEdit="GridviewEmpCanceling" >

      <Columns>

        <asp:TemplateField HeaderText="Edit">

           <ItemTemplate>
            <asp:LinkButton runat="server" ID="linkEdit" Text="Edit" CommandName="Edit"></asp:LinkButton>
           </ItemTemplate>
           <EditItemTemplate>
             <asp:LinkButton runat="server" ID="linkUpdate" Text="Update" CommandName="Update"> </asp:LinkButton>
             <asp:LinkButton runat="server" ID="linkCancel" Text="Cancel" CommandName="Cancel"> </asp:LinkButton>

           </EditItemTemplate>

        </asp:TemplateField >


         <asp:TemplateField HeaderText="EmpId">

            <ItemTemplate>
                <%# Eval("empid")%>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox runat="server" ID="txtEmpid" Text='<%# Eval("empid")%>'></asp:TextBox>
            </EditItemTemplate>

         </asp:TemplateField>

         <asp:TemplateField   HeaderText="EmpNo">

            <ItemTemplate>
                <%# Eval("empno")%>
            </ItemTemplate>
             <EditItemTemplate>
              <asp:TextBox runat="server" ID="txtEmpNo" Text='<%# Eval("empno")%>'></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>

         <asp:TemplateField HeaderText="EmpName">

            <ItemTemplate>
               <%# Eval("empname")%>
            </ItemTemplate>
            <EditItemTemplate>
             <asp:TextBox runat="server" ID="txtEmpName"  Text='<%# Eval("empname")%>'></asp:TextBox>
            </EditItemTemplate>

         </asp:TemplateField>

      </Columns>




    </asp:GridView>

      <asp:Label runat="server" ID="lblError"></asp:Label>

   </div>



在griviewupdating事件中,当您更新empno时,检查输入的empno是20还是21,如下所示,然后编写更新代码



In the griviewupdating event while you are updating the empno check whether entered empno is 20 or 21 like below then write the code for updating

int Empid = int.Parse(gridEmp.DataKeys[e.RowIndex].Value.ToString());

        GridViewRow row = gridEmp.Rows[e.RowIndex] as GridViewRow;

        TextBox txtEno = row.FindControl("txtEmpNo") as TextBox;
        TextBox txtEname = row.FindControl("txtEmpName") as TextBox;

        if (txtEno.Text == "20" || txtEno.Text == "21")
        {

            string updateCommand = "update empcode set empno=@empno, empname=@empname where empid=@empid";


            SqlConnection con = new SqlConnection(Connstr);
            {

                SqlCommand cmd = new SqlCommand(updateCommand, con);
                {
                    cmd.Parameters.AddWithValue("@empid", Empid);
                    cmd.Parameters.AddWithValue("@empno", txtEno.Text);
                    cmd.Parameters.AddWithValue("@empname", txtEname.Text);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }

            }

            gridEmp.EditIndex = -1;
            this.GetData();

        }
     
        else
        {
            lblError.Text = "Error occured please enter 20 or 21";
        }


这篇关于标签未在gridview中显示row_updating事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 21:28