ItemCommand不响应的问题

      开发中遇到了ItemCommand不响应的问题,郁闷中在网上找到了这篇对症下药的文章,共享出来。感谢共享的这位xd了。原文如下:

       在写一个DataList按钮事件时,遇到一个问题:虽然不是很有难度,但是可能会有人遇到而且会和我一样一筹莫展,直到看MSDN时,无意中发现了一句话~

      事情是这样子的:

      我需要在DataList中插入一个普通按钮,实现对Item的操作,于是,我就编辑项模版 -- 插入按钮,设置该按钮的CommandName为Button2,然后结束编辑项模版,选中该DataList,在属性对话框内按了那个黄色的小闪电标志,双击“ItemCommand”,在事件中写:

     if(e.CommandName == "Button2")
     {

    Label LabelX = (Label)e.Item.FindControl("Label1");
    string strIn = "insert into orderlog (nusername,nmoname) values ('"+username+"','"+LabelX.Text+"')";
    string reu = SC.orderAlready(username,LabelX.Text);
    if(reu == "0")
    {
     SC.INS(strIn);
     Page.RegisterStartupScript("","<script>alert('您已经成功定制了该内容,您可以返回到控制台页面点击“使用模块”直接使用,也可以在定制模版时添加到模版中。')</script>");
    }
    if(reu == "1")
    {
     Page.RegisterStartupScript("","<script>alert('该项内容您已经定制过了,不需要重复定制。')</script>");
    }
    if(reu != "0" && reu != "1")
    {
     Page.RegisterStartupScript("","<script>alert('有一个异常问题:请您联系我们的客户服务人员。')</script>");
    }

   }

      原本以为,可以很轻松地实现代码定义的操作,可是不然,断点调试发现根本就不进!于是反复调试,反复失败!

      无奈中,去到 MSDN(http://msdn.microsoft.com/library/chs/default.asp?url=/library/chs/vbcon/html/vbtskrespondingtobuttoneventsindatalistitems.asp)看看,发现有这么一段提示:“注意   如果您调用了父控件(DataListRepeaterDataGrid 控件)的 DataBind 方法,ItemCommand 事件将不会发生,原因是父控件的内容已经重置。因此,您通常不需要在每次往返时调用 DataBind 方法(即在初始化页时无需检查发回)。”

      于是,到cs文件中,将PageLoad中的DataList   DataBind代码段外加上if(!Page.IsPostBack),再调试,一切如所期望的那样,顺利执行。 

阅读更多

help me !!!ItemCommand事件不响应啊(在线等)

11-01

我是在后台创建的buttoncolumnrnDim tempBoundColumn As BoundColumnrn Dim tempButtonColumn As ButtonColumnrnrn Dim i As Integerrnrn For i = 0 To UBound(arrColumns)rn tempBoundColumn = New BoundColumnrn tempBoundColumn.DataField = "column" & irn tempBoundColumn.HeaderText = arrColumnName(i)rn tempBoundColumn.ItemStyle.Wrap = Falsern tempBoundColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Leftrn tempBoundColumn.HeaderStyle.Wrap = Falsernrn '将需要隐藏的列设置为visable=falsern If arrOnShow(i).ToLower = "no" Thenrn tempBoundColumn.Visible = Falsern End Ifrn datagridList.Columns.Add(tempBoundColumn)rn Nextrnrn tempButtonColumn = New ButtonColumnrn 'tempButtonColumn.HeaderText = "修改"rn tempButtonColumn.Text = "修改"rn tempButtonColumn.CommandName = "update"rn tempButtonColumn.ItemStyle.Wrap = Falsern tempButtonColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Leftrn 'tempBoundColumn.HeaderStyle.Wrap = Falsern datagridList.Columns.Add(tempButtonColumn)rnrn tempButtonColumn = New ButtonColumnrn 'tempButtonColumn.HeaderText = "删除" rn tempButtonColumn.Text = "删除"rn tempButtonColumn.CommandName = "delete"rn tempButtonColumn.ItemStyle.Wrap = Falsern tempButtonColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Leftrn 'tempBoundColumn.HeaderStyle.Wrap = Falsern datagridList.Columns.Add(tempButtonColumn)rn但是ItemCommand事件一点反应也没有,为什么啊rn哪位大虾告诉一下啊!!

手机图片显示与itemcommand问题

10-11

我在模拟器上测试的都可以,为何放在手机上就不显示了呢?rn 在模拟器中可以显示该图片,而且当光标移到文本框b上的时候也rn会显示okCommand,可是安装到手机上后就都不显示了。为什么阿?我rn的手机支持MIDP2.0,郁闷,劳请各位高手帮忙rn以下是我的代码rnimport javax.microedition.midlet.*;rnimport javax.microedition.lcdui.*;rnpublic class aa extends MIDlet implements CommandListenerrnrn private Command exitCommand;rn private Command okCommand; rnrn private ImageItem imageItem;rn private Image aImage;rn private TextField a;rn private TextField b;rnrn private Display display;rnrn public aa() rn display = Display.getDisplay(this);rnrn exitCommand = new Command("离开", Command.EXIT, 1);rn okCommand = new Command("抄表",Command.ITEM,1);rn a = new TextField("户 号","",10,TextField.NUMERIC);rn b = new TextField("adfasa","",10,TextField.NUMERIC);rn rn tryrn aImage = Image.createImage("/arrow.jpg");rn rn catch(Exception e);rnrn imageItem = new ImageItem("",aImage,ImageItem.LAYOUT_CENTER,"");rn rn rnrn public void startApp() rn Form aForm = new Form("ImageItem示范");rnrn aForm.append(imageItem);rn aForm.append(b);rn aForm.append(a);rn a.addCommand(okCommand);rn rnrn aForm.addCommand(exitCommand);rnrn aForm.setCommandListener(this);rn display.setCurrent(aForm);rn rnrn public void pauseApp() rnrn public void destroyApp(boolean unconditional) rnrn public void commandAction(Command c, Displayable s) rn if (c == exitCommand) rn destroyApp(false);rn notifyDestroyed();rn rn rnrnrn

没有更多推荐了,返回首页