1

I'm having some problems with my code. Basically I want a DDL that has a list of values from a table sorted by the primary key. When an item is selected and a button is clicked, a Grid View shows the rest of the information about the respective record. I'll post the code I have now. For some reason, nothing appears in the DDL at all and I can't seem to figure out why.

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    void Page_Load()
    {
        if (!Page.IsPostBack)
        {
            grv1.DataSource = srcCSC;
            grv1.DataBind();
        }
    }


    void btn1_click(object sender, EventArgs e)
    {

        DataSourceSelectArguments objSelectArg = new DataSourceSelectArguments();
        DataView objView = (DataView)srcCSC.Select(objSelectArg);

        srcCSC.Select(objSelectArg);

        //rebind
        grv1.DataSource = srcCSC;
        grv1.DataBind();
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            City:
            <asp:DropDownList ID="ddlCity" runat="server" DataSourceID="srcCSC" DataTextField="City" DataValueField="City"  /><br />


            <asp:SqlDataSource
                ID="srcCSC"
                runat="server"
                ConnectionString="<%$ ConnectionStrings:xyz1%>"
                SelectCommand="Select City, CompanyName, ContactName, Relationship From CustomerSupplierCity Where City=@City">
                <SelectParameters>
                    <asp:ControlParameter ControlID="ddlCity" Name="City" />
            </SelectParameters>
     </asp:SqlDataSource>
     <br />
            <br />
            <asp:Button ID="btn1" Text="Select" runat="server"
                OnClick="btn1_click" />

            <asp:GridView ID="grv1" runat="server" AllowPaging="true" DataKeyNames="City,CompanyName,Relationship" />

        </div>
    </form>
</body>
</html>

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.