Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need Quick ASP.Net Lesson
Message
General information
Forum:
ASP.NET
Category:
Other
Title:
Need Quick ASP.Net Lesson
Miscellaneous
Thread ID:
01454541
Message ID:
01454541
Views:
103
As I'm VERY new to ASP.Net, I'm not sure I understand how things work.

I put together a composite usercontrol. It has a listbox that shows user roles. When a role is selected, the RoleName, RoleCode, and
Description are pulled from data and displayed in 3 textboxes - at leats that's what the goal is.

At this point when I run it the listbox is populated. But the DataSet that's bound to the list is then null when I attempt to access
it from SelectedIndexChanged. I'm guessing that I'm doing this wrong.

Here's the code.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using Marois.Common.DataAccess;

public partial class crlRoles : System.Web.UI.UserControl
{
    private DataSet dsRoles = null;
    private DataAccess DataLayer = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataLayer = new DataAccess();
            _LoadList();
        }
    }

    private void _LoadList()
    {
        DataLayer.ProviderInvariantName = "System.Data.SqlClient";
        DataLayer.ConnectionString = ConfigurationManager.ConnectionStrings["ApexGlobalConnectionString"].ConnectionString;

        dsRoles = DataLayer.ExecuteQuery("as_GetRole", CommandType.StoredProcedure);

        lstRoles.DataSource = dsRoles.Tables[0];
        lstRoles.DataTextField = "RoleName";
        lstRoles.DataBind();
    }

    protected void lstRoles_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (lstRoles.SelectedIndex > -1)
        {
            int RoleKey = (int)dsRoles.Tables[0].Rows[lstRoles.SelectedIndex]["RoleKey"];

            SqlParameter pRoleKey = new SqlParameter("@RoleKey", RoleKey);
            List<DbParameter> Params = new List<DbParameter>();
            Params.Add(pRoleKey);

            dsRoles = DataLayer.ExecuteQuery("as_GetRole", Params, CommandType.StoredProcedure);

            txtRoleName.Text = dsRoles.Tables[0].Rows[0]["Name"].ToString();
            txtRoleCode.Text = dsRoles.Tables[0].Rows[0]["RoleCode"].ToString();
            txtDescription.Text = dsRoles.Tables[0].Rows[0]["Description"].ToString();
        }
    }
}
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Next
Reply
Map
View

Click here to load this message in the networking platform