Solved

moving sql variable values from a aspx page to local varibles

Posted on 2006-10-28
5
252 Views
Last Modified: 2010-04-16
I am using a SqlDataSource (in asp 2.0 aspx page)  with a Gridview control, I would like to PrePopulate  the textboxes of a formview controls (Insert mode) whith the results (variable values) from the  Gridview.  I’m using C#.

      SqlDataSource1
SELECT  userId, rate, Lname, Fname
FROM   empl

I want to populate the following varibles in my aspx page. And prepopulat the textBoxes in a FormView control in Insert mode

Int    UserID
Int   Payrate
String  Lname
String  Fname

Can some one show me how to do this?
Thanks!
0
Comment
Question by:bmanmike39
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 12

Accepted Solution

by:
deanvanrooyen earned 500 total points
ID: 17831596
this is how you can manually bind a control or make your own form view

this is just with a repeater, there is a button that does the updating to give you an idea, this could even just be an html table with some server controls...

        <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand"  >
        <ItemTemplate>
             <asp:Label ID="label1" Text='<%# Bind("ProductID") %>' runat="server" Width="50"  ></asp:Label>
             <asp:CheckBox id="chk" runat="server" Text="Discontinued?" Checked='<%# System.Convert.ToBoolean(Eval("Discontinued")) %>' Width="50"/>
             <asp:TextBox id="textbox" runat="server" Text='<%# Bind("Description") %>'
             <asp:Button id="btnUpdate" Runat="server" Text="Update" CommandName="Update" CommandArgument='<%# Eval("productID") %>' Font-Size="12px" Width="50"></asp:Button>
             <br />
         </ItemTemplate>
        </asp:Repeater>



    public void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Int32 id = System.Convert.ToInt32(((Label)e.Item.FindControl("label1")).Text);
        Int16 check = System.Convert.ToInt16(((CheckBox)e.Item.FindControl("chk")).Checked);
        TextBox tb = (TextBox )e.Item.FindControl("textbox");
        //update the db
        string strcon = SqlDataSource1.ConnectionString;
        System.Data.SqlClient.SqlConnection sqlCon = new System.Data.SqlClient.SqlConnection(strcon);
        System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("update products set discontinued = @check,description = @desc  where productid = @id", sqlCon);
        sqlCmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
        sqlCmd.Parameters.Add("@check", SqlDbType.Int).Value = check;
        sqlCmd.Parameters.Add("@desc ", SqlDbType.Int).Value = tb.Text;
       
        try
        {
            sqlCon.Open();
            sqlCmd.ExecuteNonQuery();
            sqlCon.Close();
            //rebind the repeater
        }
        catch(Exception me)
        {

        }  
    }

             
0
 

Author Comment

by:bmanmike39
ID: 18047352
I have had to address a urgent  project and have not been able to test the answer given.  I am hoping to get back to that project in the next week or so.  Sorry about the time.  So please leave it posted for now, if that is possible.

Thank you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

623 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