Answered by:
label value in get set

Question
-
User-807418713 posted
Hello
I have one Label9 It has some value i want to pass this label in my below code how to do so
public class MyModel { private string issueBatch; public string IssueBatch { get { return issueBatch; } set { issueBatch = value; } } }
Thanking You
Wednesday, March 10, 2021 8:51 PM
Answers
-
User-1330468790 posted
Hi Gopi.MCA,
What do you mean by passing this label in the code?
It would be much helpful to understand the problem if you specify the problem with more details.
If you want to pass the 'Text' value from the label 'Label9', you could simply instantiate an instance from the class MyModel and assign the value to the property 'issueBatch'.
For example, I have "123" as the value of the label 'Label9' then you could do as follow.
Page:
<form id="form1" runat="server"> <div> <asp:Label runat="server" Text="123" ID="Label9"></asp:Label> </div> <div> Result: <%= myModel.IssueBatch %> </div> <asp:Button ID="GetValueBtn" runat="server" Text="GetValue" OnClick="GetValueBtn_Click"/> </form>
Code behind:
public MyModel myModel = new MyModel(); protected void Page_Load(object sender, EventArgs e) { } protected void GetValueBtn_Click(object sender, EventArgs e) { myModel.IssueBatch = Label9.Text; } public class MyModel { private string issueBatch; public string IssueBatch { get { return issueBatch; } set { issueBatch = value; } } }
Demo:
Reference:
Properties (C# Programming Guide)
Hope helps.
Best regards,
Sean
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 11, 2021 2:48 AM
All replies
-
User-1330468790 posted
Hi Gopi.MCA,
What do you mean by passing this label in the code?
It would be much helpful to understand the problem if you specify the problem with more details.
If you want to pass the 'Text' value from the label 'Label9', you could simply instantiate an instance from the class MyModel and assign the value to the property 'issueBatch'.
For example, I have "123" as the value of the label 'Label9' then you could do as follow.
Page:
<form id="form1" runat="server"> <div> <asp:Label runat="server" Text="123" ID="Label9"></asp:Label> </div> <div> Result: <%= myModel.IssueBatch %> </div> <asp:Button ID="GetValueBtn" runat="server" Text="GetValue" OnClick="GetValueBtn_Click"/> </form>
Code behind:
public MyModel myModel = new MyModel(); protected void Page_Load(object sender, EventArgs e) { } protected void GetValueBtn_Click(object sender, EventArgs e) { myModel.IssueBatch = Label9.Text; } public class MyModel { private string issueBatch; public string IssueBatch { get { return issueBatch; } set { issueBatch = value; } } }
Demo:
Reference:
Properties (C# Programming Guide)
Hope helps.
Best regards,
Sean
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 11, 2021 2:48 AM -
User-1545767719 posted
var model = new MyModel(); model.IssueBatch = Labale9.Text;
Thursday, March 11, 2021 3:17 AM -
User-807418713 posted
Hello
Still its not showing here
public static void InsertData(List<MyModel> myModels) { foreach (MyModel item in myModels) { SqlConnection zcon = new SqlConnection(ConfigurationManager.ConnectionStrings["invConnectionString"].ConnectionString); zcon.Open(); SqlCommand ck = new SqlCommand("Insert into Store_Descp(process_issue_no,process_name)values(@process_issue_no,@process_name)", zcon); ck.Parameters.Add(new SqlParameter("@process_issue_no", "1 Issues")); ck.Parameters.Add(new SqlParameter("@process_name", "here i want to pass my label value")); } }
how to pass my label value in process_name parameter?
Thanking You
Thursday, March 11, 2021 6:08 AM -
User-1330468790 posted
Hi Gopi.MCA,
You should show us a whole workflow from fetching the value of the label to assigning the value to the model.
In that way, we are able to know where the problem is without guessing.
Could you please provide more information?
Including:
- The codes you currently have for aspx page and code behind.
- Why do you think the codes are not working?
- What have you done before calling the method?
Really appreciate your further information.
Best regards,
Sean
Thursday, March 11, 2021 9:20 AM