Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

using bound data outside datalist (and inside datalist at the same time)

Posted on 2006-05-01
12
Medium Priority
?
271 Views
Last Modified: 2012-05-05
I have a data list on my page populated by the following code:

protected void Page_Load(object sender, EventArgs e)
    {
        string strUserEmail = (string)(Session["UserEmail"]);
        EmployeeDetails(strUserEmail);
    }

private void EmployeeDetails(string userEmailString)
    {
        dlOneEmployee.DataSource = Orrweb.getEmployeeInfo(userEmailString);
        dlOneEmployee.DataBind();
    }


this page also contains a form for submission of data. In that form, I'd like to have a few hidden fields that contain that datalist data, so I can pass it to the database along with the form content.

How do I go about doing that?

I've tried using an asp:label (in the datalist template) with the text set to the dataBinder data from the data list, but it doesn't work. I've tried to set up a label outside the datalist and, in the c# code-behind, set the value of that label's .Text to the bound data, but I can't figure out how to go about doing that.

I made the attempt like so:

protected void Page_Load(object sender, EventArgs e)
    {
        string strUserEmail = (string)(Session["UserEmail"]);
        EmployeeDetails(strUserEmail);
        lblTicketCreatorName.Text = DataBinder.Eval(Container.DataItem, "first_name") + " " + DataBinder.Eval(Container.DataItem, "last_name");
    }


Again, no luck there, but you can at least see what I'm trying to do.
0
Comment
Question by:Paul Kahl
  • 7
  • 3
11 Comments
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16580990
to make this a tad easier to understand:

page is setup with a datalist at page top, displaying user info, static/readonly.

under that data list is set of form fields, which the user will select and manipulate with data before submitting.

on submission, I need to collect that data, to use in validation and setting up a database update call via parameterized sproc.

The function that grabs the data on submit currently is:

protected void btnRequestSubmit_Click(object sender, EventArgs e)
    {
        StringBuilder sBuild = new StringBuilder();
       
        sBuild.Append("<p><strong>Results:</strong><br /> ");
        sBuild.Append("<em>Request Type:</em> ");
        sBuild.Append(ddlRequestType.SelectedItem.Value);
        sBuild.Append("<br /> ");
        sBuild.Append("<em>Short Description:</em> ");
        sBuild.Append(txtRequestDesc.Text);
        sBuild.Append("<br /> ");
        sBuild.Append("<em>Ticket Creator Name:</em> ");
        sBuild.Append(STUFF GOES HERE);
        sBuild.Append("</p>");

        lblDisplayResults.Text = sBuild.ToString();
    }


Where it says "STUFF GOES HERE" is where I'm attempting to read in this datalist displayed data.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16582590
Something like this, maybe:

    foreach (DataListItem item in this.dataList1.Items)
    {
      DataRowView row = (DataRowView)item.DataItem;
      string name = row["Name"].ToString();
    }

Bob
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16588795
what is "Name" in the string name... line?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Paul Kahl
ID: 16590231
Nevermind... Here's what I was attempting:

protected void Page_Load(object sender, EventArgs e)
    {
        string strUserEmail = (string)(Session["UserEmail"]);

        if (isLoggedIn(strUserEmail))
        {
            EmployeeDetails(strUserEmail);

            FillHiddenFields(strUserEmail);
        }
        else
        {
            Response.Redirect("login.aspx");
        }
    }

//FillHiddenFields will run the data source again as follows:
private void FillHiddenFields(string userEmailString)
    {
        DataSet ds = new DataSet();
        DataTable dt;
        DataRow row;

        ds = Orrweb.getEmployeeInfo(userEmailString);
        dt = ds.Tables[0];
               
        row = dt.Rows[0];

        lbl_vchrSRCreatorEmail.Text = row[2].ToString();
        lblTicketCreatorName.Text = row[1].ToString();
    }

easy enough, once it occured to me. :)
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16590239
the employee details function, in case one is curious:

private void EmployeeDetails(string userEmailString)
    {
        dlOneEmployee.DataSource = Orrweb.getEmployeeInfo(userEmailString);
        dlOneEmployee.DataBind();
    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16596088
"Name" was an arbitrary field name.  You could use an value that occurs in your table, like last_name, or first_name.

Are you still looking for a solution?

Bob
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16597905
I believe I landed on the solution as detailed above.

I attempted to use the table loop you mentioned, and just got "object does not exist" errors, but I'm going to play with it some more and see if I can make it run, because I think I see some other uses for it. :)

Thanks for helpin me wander my way through this. C# might not be my friend yet, but we're at least on speaking terms.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16597958
LOL!!

I was making some assumptions, and guessing at what you really wanted to achieve.  I took a SWAG, and hoped that it could be modified to fit.  Sorta like using a sledge hammer to get a square peg in a round hole.

Bob
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16598118
If the peg fits, the way it got there is unimportant :)
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16650747
this question has been answered. Request it be closed, but maintained for other's use.
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 16831184
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question