0

Sorry for repeating the question but I have searched almost all the questions on stackoverflow but didn't find any solution. Im implementing a gridview where im using a WHERE clause, but got in gridview.

here is the code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    DataSourceID="SqlDS1">
    <Columns>
        <asp:BoundField DataField="alert_title" HeaderText="alert_title" 
            SortExpression="alert_title" />
        <asp:BoundField DataField="alert_desc" HeaderText="alert_desc" 
            SortExpression="alert_desc" />
        <asp:BoundField DataField="alert_deadline" HeaderText="alert_deadline" 
            SortExpression="alert_deadline" />
    </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDS1" runat="server" 
    ConnectionString="<%$ ConnectionStrings:SQL %>" 
    SelectCommand="SELECT [alert_title], [alert_desc], [alert_deadline] FROM [Table_Alerts] WHERE [alert_owner] = @alert_owner ">
    <SelectParameters>
        <asp:Parameter Name="alert_owner" Type="String" />
    </SelectParameters>
</asp:SqlDataSource>

aspx.cs file

 protected void Page_Load(object sender, EventArgs e)
{
        string Value = "muneeb";
        //Parameter par = new Parameter("@alert_owner", DbType.String,Value);
        //SqlDS1.SelectParameters.Add(par);

        SqlDS1.SelectParameters["@alert_owner"].DefaultValue = "muneeb";
}

after implementing this got an expection at

        SqlDS1.SelectParameters["@alert_owner"].DefaultValue = "muneeb";

can some please tell me where I went wrong? or how can i fix it. Thanks in Advance

2
  • 1
    Try specifying the Select command and Select parameters collection from the code behind, like in this thread. Commented May 11, 2014 at 15:23
  • I have tried this too. but still got nothing in gridview Commented May 11, 2014 at 15:58

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.