Please help me solve this code .
Thanks you in advance .
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
{
SqlDataSource s = (SqlDataSource)e.Row.FindControl("SqlDataSource2");
s.SelectParameters[0].DefaultValue = e.Row.Cells[1].Text;
}
my coding
public partial class trygrid : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlDataSource s = (SqlDataSource)e.Row.FindControl("SqlDataSource2");
s.SelectParameters[0].DefaultValue = e.Row.Cells[1].Text;
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton l_btn = (LinkButton)sender;
GridViewRow gvr = (GridViewRow)l_btn.NamingContainer;
Panel p1 = (Panel)gvr.FindControl("Panel3");
LinkButton lb1 = (LinkButton)gvr.FindControl("LinkButton1");
if (p1.Visible == false)
{
p1.Visible = true;
lb1.Text = "-";
}
else if (p1.Visible == true)
{
p1.Visible = false;
lb1.Text = "+";
}
GridView gv2 = (GridView)l_btn.FindControl("GridView2");
gv2.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
}
}
my design
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table style="width: 100%">
<tr>
<td>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
onrowdatabound="GridView1_RowDataBound" Width="244px">
<Columns>
<asp:BoundField DataField="l_no" HeaderText="l_no"
SortExpression="l_no" />
<asp:BoundField DataField="nam_dep" HeaderText="nam_dep"
SortExpression="nam_dep" />
<asp:BoundField DataField="no_deo" HeaderText="no_deo"
SortExpression="no_deo" />
<asp:BoundField DataField="no_mon" HeaderText="no_mon"
SortExpression="no_mon" />
<asp:BoundField DataField="le_yn" HeaderText="le_yn"
SortExpression="le_yn" />
<asp:BoundField DataField="dd_yn" HeaderText="dd_yn"
SortExpression="dd_yn" />
</Columns>
<EmptyDataTemplate>
<asp:LinkButton ID="LinkButton11" runat="server"
Font-Size="X-Large" Font-Underline="False" onclick="LinkButton1_Click ">+</asp:LinkButton>
<asp:Panel ID="Panel3" runat="server" Height="127px"
Visible="False">
<asp:GridView ID="GridView2" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="req_id" HeaderText="req_id"
InsertVisible="False" ReadOnly="True" SortExpression="req_id" />
<asp:BoundField DataField="l_no" HeaderText="l_no"
SortExpression="l_no" />
<asp:BoundField DataField="nam_dep" HeaderText="nam_dep"
SortExpression="nam_dep" />
<asp:BoundField DataField="date" HeaderText="date"
SortExpression="date" />
<asp:BoundField DataField="no_deo" HeaderText="no_deo"
SortExpression="no_deo" />
<asp:BoundField DataField="no_mon" HeaderText="no_mon"
SortExpression="no_mon" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:XYZConnectionString %>"
SelectCommand="SELECT * FROM [request_dept] WHERE ([l_no] = @l_no)">
<SelectParameters>
<asp:Parameter Name="l_no" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Panel>
</EmptyDataTemplate>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:XYZConnectionString %>"
SelectCommand="SELECT * FROM [viewyn]"></asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</td>
</tr>
</table>
</asp:Content>