尝试插入复选框列表(修改问题并添加额外代码) [英] trying to insert with a checkbox list (revised the question and added extra code)

查看:80
本文介绍了尝试插入复选框列表(修改问题并添加额外代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3层架构...试图用复选框列表插入一些内容...



这段代码甚至可以工作吗?每次我尝试插入...我都会失败。



  protected   void  submitButton_Click( object  sender,EventArgs e)
{
< span class =code-comment> // 让我们先验证页面
如果(!Page.IsValid)
return ;

int intResult = 0 ;
// 页面有效,让我们继续并插入记录
// 实例化BAL对象
sBLL scBLL = new sBLL();
// 实例化我们必须处理的对象
sBO scBO = < span class =code-keyword> new sBO();
// 设置对象的属性
sDAL scdal = new sDAL();

scBO.scholarshipName = scNameText.Text;
scBO.orgID = 1 ;


尝试
{
intResult = scBLL.Insert(scBO);
if (intResult > 0
lblMessage.Text = 成功插入新记录。;
else
lblMessage.Text = 失败;

}
catch (例外ee)
{
lblMessage.Text = ee.Message.ToString ();
}
最后
{
int sID = scBO.sID;
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected)
{
mascidBLL masciBLL = new mascidBLL() ;
mascidBO masciBO = new mascidBO();
masciBO.sID = sID;
masciBO.majorID = int .Parse(li.Value);
}
}
}


scBO = null ;
scBLL = null ;
}




如果有帮助,
i有bll,bo和dal。



提前感谢

解决方案

您从未添加或插入任何内容。看一看:所有控件都有一些父级。要插入任何内容,首先应创建一个新对象。这意味着调用一个(恰好一个)构造函数。下一步,您需要在父元素和新元素之间建立父子关系。所以,你需要一个构造函数调用和一个Insert / Add调用。



因为你虽然很接近,但我相信我可以把剩下的留给你。特别是如果您没有真正告诉我们 ListItem CheckBoxList 类的确切类型。您是否知道.NET中有多个UI库。即使我能猜到它是什么,我认为猜测并不适合在这里做。你问了一个问题,你指定了与你有关的所有问题,好吗?特别是,您应该标记UI库或应用程序类型。



现在,让我们看看您是否可以完成问题的解决方案。



嗯,还不清楚为什么你称之为批量以及它如何与更新(什么)相关。如果您有一些后续问题,我希望您解释一切,不要含糊不清。



祝你好运,

-SA

i have a 3-tier architecture...trying to insert something with checkboxlist...

would this bit of code even work? every time i try to insert...i get a fail.

protected void submitButton_Click(object sender, EventArgs e)
{
    //Lets validate the page first
    if (!Page.IsValid)
        return;

    int intResult = 0;
    // Page is valid, lets go ahead and insert records
    // Instantiate BAL object
    sBLL scBLL = new sBLL();
    // Instantiate the object we have to deal with
    sBO scBO = new sBO();
    // set the properties of the object
    sDAL scdal = new sDAL();

    scBO.scholarshipName = scNameText.Text;
    scBO.orgID = 1;


    try
    {
        intResult = scBLL.Insert(scBO);
        if (intResult > 0)
            lblMessage.Text = "New record inserted successfully.";
        else
            lblMessage.Text = "failed";

    }
    catch (Exception ee)
    {
        lblMessage.Text = ee.Message.ToString();
    }
    finally
    {
        int sID = scBO.sID;
        foreach (ListItem li in CheckBoxList1.Items)
        {
            if (li.Selected)
            {
                mascidBLL masciBLL = new mascidBLL();
                mascidBO masciBO = new mascidBO();
                masciBO.sID = sID;
                masciBO.majorID = int.Parse(li.Value);
            }
        }
    }


        scBO = null;
        scBLL = null;
    }



i have a bll, bo and a dal if that helps.

thanks in advance

解决方案

You never added or inserted anything. Take a look: all controls have some parent. To insert anything, you should first create a new object. This means a call to one (exactly one) constructor. Next step, you need to establish a parent-child relation between parent and a new element. So, you need one constructor call and one Insert/Add call.

As you though you were close, I trust I can leave the rest to you. Especially in case you did not really tell us an exact type of the ListItem or CheckBoxList classes. Did you know that there are more then one UI library in .NET. Even though I can guess what is it, I think guesswork is not an appropriate thing to do here. You ask a question, you specify all which is relevant to you question, OK? In particular, you should tag UI library or application type.

Now, let''s see if you can complete the solution of the problem.

Well, also, it''s not clear why do you call it "batch" and how it this related to "update" (of what). If you have some follow-up questions, I hope you explain everything the way leaving no ambiguity.

Good luck,
—SA


这篇关于尝试插入复选框列表(修改问题并添加额外代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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