如何在下一个函数中使用值 [英] How to use value in next function

查看:72
本文介绍了如何在下一个函数中使用值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  protected   void  rptGroupMember_ItemCommand( object  source,RepeaterCommandEventArgs e)
{
string groupID = ;
switch (e.CommandName)
{
case 点击
{
PopulateUserList(WorldEvolveModel.TherapistLevel.All.ToString() );
HiddenField hid =((LinkBut​​ton)e.CommandSource).FindControl( hfMessageGroupID as HiddenField;
// 这里我得到了id。
groupID = hid.Value的ToString();
}
break ;
默认
{
txtSearchMember.Text = 无法获取群组......;
}
break ;
}
}

// 获取所选成员的方法从弹出窗口中将它们保存在数据库中
受保护 void SaveSelectedGroupMember()
{
MessageGroupMemberDAL dal = new MessageGroupMemberDAL();
MessageGroupMemberModel model = new MessageGroupMemberModel();
MessageGroupDAL dalMG = new MessageGroupDAL();

string [] str = hfSelectedMembeID.Value.Split(' );

for int i = 0 ; i < str.Length; i ++)
{
/ / Get_UserProfiler(HttpContext.Current.User.Identity.Name);
model.GroupMemberID = 0 ;

// 在第一个函数中我评论了code.that我在这里得到id.i想要用来代替3。
model.MessageGroupID = 3 ;
model.MemberID = Convert.ToInt32(str [i]);
model.MemberType = test;

dal.InsertUpdate_MessageGroupMembers(model);
}
}





我该怎么办...



plz帮助我...

解决方案

您可以像这样使用ViewState:

1.分配groupid in rptGroupMember_ItemCommand函数

ViewState [groupID] = hid.Value.ToString();



2。在SaveSelectedGroupMember函数中使用它

model.GroupMemberID = ViewState [groupID] ; //相应地在此处投射


亲爱的朋友。 ,



只需尝试以下任何一个步骤..



1.你只需声明字符串groupID是私人的功能之外。或者

2.使用查看状态或

3.在表单中创建一个新的隐藏字段控件。并将组ID值分配给新的隐藏字段值。并在你的函数中使用新的隐藏字段值..



我希望这些信息对你有用。



谢谢和问候



Angappan.S


在这个类中,你可以拥有一个名为_hid的全局变量。

  int  _hid =  0 ; 



最好在构造函数中将其初始化为0,或者在全局声明它时。



然后当您在第一种方法中获取隐藏时,只需将其保存到_hid然后再使用它。

 _ hid = hid; 





第二种方法内:

< pre lang =   cs> for( int  i =  0 ; i <  str.Length; i ++)
{
// Get_UserProfiler(HttpContext.Current.User.Identity.Name);
model.GroupMemberID = 0 ;

model.MessageGroupID = _hid;
model.MemberID = Convert.ToInt32(str [i]);
model.MemberType = test;

dal.InsertUpdate_MessageGroupMembers(model);
}





在第二种方法中,可能有一个if语句来检查_hid是否为0并对该值执行某些操作。


protected void rptGroupMember_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            string groupID = "";
            switch (e.CommandName)
            {
                case "Click":
                    {
                        PopulateUserList(WorldEvolveModel.TherapistLevel.All.ToString());
                        HiddenField hid = ((LinkButton)e.CommandSource).FindControl("hfMessageGroupID") as HiddenField;
//here i am getting the id.
                        groupID = hid.Value.ToString();
                    }
                    break;
                default:
                    {
                        txtSearchMember.Text = "Can't Get Groups...";
                    }
                    break;
            }
        }

        //Method for get the selected member from popup and save them in database
        protected void SaveSelectedGroupMember()
        {
            MessageGroupMemberDAL dal = new MessageGroupMemberDAL();
            MessageGroupMemberModel model = new MessageGroupMemberModel();
            MessageGroupDAL dalMG = new MessageGroupDAL();

            string[] str = hfSelectedMembeID.Value.Split(',');

            for (int i = 0; i < str.Length; i++)
            {
                //Get_UserProfiler(HttpContext.Current.User.Identity.Name);
                model.GroupMemberID = 0;

//in first function i commented code.that i m getting id here.i want to use that is here in place of 3.
                model.MessageGroupID = 3;
                model.MemberID = Convert.ToInt32(str[i]);
                model.MemberType = "test";

                dal.InsertUpdate_MessageGroupMembers(model);
            }
        }



how can i do this...

plz help me...

解决方案

You can use ViewState like this:
1. Assign groupid in rptGroupMember_ItemCommand function
ViewState["groupID"] = hid.Value.ToString();

2. use this in SaveSelectedGroupMember function
model.GroupMemberID = ViewState["groupID"] ;// cast here accordingly


Dear Friend.,

just try the following steps any one..

1.you just declare that string groupID is private an outside of function. or
2.use view state or
3.create one new hidden field control in your form. and assign group id value to new hidden field value. and use new hidden field value to in your function..

I hope this information helpful to you.,

Thanks and regards

Angappan.S


In this class you can have a global variable called _hid.

int _hid = 0;


Its better to initialize it to 0 in the constructor or as you declare it globally.

Then as you are getting the hid in the 1st method just save it to _hid and then use it later.

_hid = hid;



Inside the second method:

<pre lang="cs">for (int i = 0; i < str.Length; i++)
            {
                //Get_UserProfiler(HttpContext.Current.User.Identity.Name);
                model.GroupMemberID = 0;
               
                model.MessageGroupID = _hid;
                model.MemberID = Convert.ToInt32(str[i]);
                model.MemberType = "test";

                dal.InsertUpdate_MessageGroupMembers(model);
            }



In the second method maybe have a if statement to check if _hid is 0 and do something with the value.


这篇关于如何在下一个函数中使用值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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