Hi, This is muskan. I have problem in C#.net . I started learning C# . In this context I have following problem. How can I used Selectedvalue of Combobox on page load event. What i want is like I used to use call class function in which 2 value saved. First is ID and Second is UserName. The UserName show in Combobox and when I save the ID saved. But In C# I can not know how to do this. Please help me to do this. I used following Function at Class level:
// Public Function GetValueInDropDown(ByVal cmbName As DropDownList, ByVal strFirstItem As String, ByVal StorProcName As String, ByVal dbparam As String, ByVal usparam As String, ByVal dbparam1 As String, ByVal usparam1 As String) Dim ds As New DataSet ds = Me.GetDataSet(StorProcName, dbparam, usparam, dbparam1, usparam1) cmbName.Items.Clear() cmbName.Items.Add(New ListItem(strFirstItem, "0")) For Each dr As DataRow In ds.Tables(0).Rows cmbName.Items.Add(New ListItem(dr(1), dr(0))) Next End Function
//
And Call this function on load Event like this: //
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If IsPostBack = False Then obj.GetValueInDropDown(cmbUserLavel, "Select", "sp_Get_UserLavel") End If End Sub This will give result to show UserName but when I saved(cmbUserLabel.selectedvalue) the ID is Saved instead of UserName . Please help me.
|
| Author: Padma 30 May 2007 | Member Level: Diamond | Rating: Points: 2 |
so get selectitem.text instead of getting selectedvalue
|
| Author: ChandraShekarThota 27 Jun 2007 | Member Level: Diamond | Rating: Points: 2 |
use selectitem.text
|