kaushik guru

kaushik guru

  • 1.4k
  • 252
  • 27.3k

selecteditem.value always shows null or zero

Apr 8 2020 11:02 PM
i am selecting a value from dropdown and passing it to store procedure but the selected index value always becomes null or zero . kindly guide
 
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DMS.Report
{
    public partial class UserMatrixRights : System.Web.UI.Page
    {

        DataSet ds = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if(ddlroles.Text == "Users")
            {
                LblError.Visible = false;
                lblusers.Text = "Users";
                Loadusers();
            }
            else if (ddlroles.Text == "Roles")
            {
                LblError.Visible = false;
                lblusers.Text = "Roles";
                Loadroles();
            }
        }

        private void Loadusers()
        {
            try
            {
                DataSet dsUsers = null;
                using (GeneralInfo GenInfo = new GeneralInfo(General.ConnString()))
                {
                    dsUsers = GenInfo.GetAllUsers();
                    if (dsUsers != null)
                    {
                        if (dsUsers.Tables.Count > 0)
                        {
                            if (dsUsers.Tables[0].Rows.Count > 0)
                            {
                                DataRow drUsersLoad;
                                drUsersLoad = dsUsers.Tables[0].NewRow();
                                drUsersLoad["User_RoleId"] = 0;
                                drUsersLoad["User_Name"] = "ALL";
                                dsUsers.Tables[0].Rows.InsertAt(drUsersLoad, 0);
                               
                                ddusers.DataTextField = "User_Name";
                                ddusers.DataValueField = "User_RoleId";
                                ddusers.DataSource = dsUsers.Tables[0];
                                ddusers.DataSource = dsUsers.Tables[0];
                                ddusers.DataBind();
                               // ddusers.Items.Insert(0, "--Select--");
                            }
                        }
                    }
                }
            }
            catch (GeneralInfoException GeneralEx)
            {
                LblError.Text = GeneralEx.ErrorDescription;
                //log.Error("AssetMaintenance_LoadCategory_Details", GeneralEx);
            }
            catch (Exception ex)
            {
                LblError.Text = GeneralException.Errcode(ex);
                //log.Error("AssetMaintenance_LoadCategory_Details", ex);
            }
        }

        private void Loadroles()
        {

            try
            {
                DataSet dsUsersgp = null;
                using (GeneralInfo GenInfo = new GeneralInfo(General.ConnString()))
                {
                    dsUsersgp = GenInfo.GetAllUsersGroups();
                    if (dsUsersgp != null)
                    {
                        if (dsUsersgp.Tables.Count > 0)
                        {
                            if (dsUsersgp.Tables[0].Rows.Count > 0)
                            {
                                DataRow drUsersgpLoad;
                                drUsersgpLoad = dsUsersgp.Tables[0].NewRow();
                                drUsersgpLoad["Role_Id"] = 0;
                                drUsersgpLoad["Role_Description"] = "ALL";
                                dsUsersgp.Tables[0].Rows.InsertAt(drUsersgpLoad, 0);

                                ddusers.DataTextField = "Role_Description";
                                ddusers.DataValueField = "Role_Id";
                                ddusers.DataSource = dsUsersgp.Tables[0];
                                ddusers.DataBind();
                            }
                        }
                    }
                }
            }
            catch (GeneralInfoException GeneralEx)
            {
                LblError.Text = GeneralEx.ErrorDescription;
                //log.Error("AssetMaintenance_LoadCategory_Details", GeneralEx);
            }
            catch (Exception ex)
            {
                LblError.Text = GeneralException.Errcode(ex);
                //log.Error("AssetMaintenance_LoadCategory_Details", ex);
            }
        }

        protected void BtnView_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                getreport();

            }
            catch (Exception ex)
            {
            }


        }

        private void getreport()
        {
            string sValue = ddusers.SelectedItem.Value;
             (sValue always becomes null or 0)
            if (ddlroles.Text == "Users")
            {
                using (MasterManagement mMgmt = new MasterManagement(General.ConnString()))
                {
                    ds = mMgmt.GetUserReport(sValue);
                }
            }
                else

                {
                }

            }

        }
    }
 
 

Answers (1)