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

M A.
  • 949
  • 2
  • 12
  • 29
  • 1
    Try specifying the Select command and Select parameters collection from the code behind, like in this [thread](http://stackoverflow.com/questions/485821/how-to-pass-variable-to-selectcommand-of-sqldatasource). – CopyPasteDev May 11 '14 at 15:23
  • I have tried this too. but still got nothing in gridview – M A. May 11 '14 at 15:58

0 Answers0