Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

moving sql variable values from a aspx page to local varibles

Posted on 2006-10-28
5
Medium Priority
?
253 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

705 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