Server Error in '/' Application.
Value cannot be null.
Parameter name: source
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.ArgumentNullException: Value cannot be null.
Parameter name: source
Source Error:
Line 176: int index = Convert.ToInt32(e.CommandArgument);
Line 177: DataTable dt = (DataTable)ViewState["DataTable"];
Line 178: IEnumerable<DataRow> query = from i in dt.AsEnumerable()
Line 179: where i.Field<int>("Id").Equals(index)
Line 180: select i;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
if (!this.IsPostBack)
{
username = this.Page.User.Identity.Name;
// DataTable dt = GetProfile();
GetMergedAll.DataSource = dt;
ViewState["DataTable"] = dt;
GetMergedAll.DataSource = dt;
GetMergedAll.DataBind();
// if (dt.Rows.Count > 0)
{
}
}
}
this.GetData();
}
private void GetData()
{
string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
string GetData = "GetUserPOSTS";
using (SqlConnection con = new SqlConnection(str))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(GetData, con))
{
cmd.CommandType = CommandType.StoredProcedure;
// cmd.Parameters.AddWithValue("@Name", Request.QueryString["Id"].ToString());
cmd.Parameters.AddWithValue("@UserName", username);
cmd.Parameters.AddWithValue("@Id", Id);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
GetMergedAll.DataSource = dt;
GetMergedAll.DataBind();
}
}
}
protected void linkpost_Click(object sender, EventArgs e)
{
if (this.Page.User.Identity.IsAuthenticated)
{
string username = this.Page.User.Identity.Name;
{
string tendString = TextBixcomment.Text.Trim();
string strname = ""; // ADDED
if (FileUploadImage.HasFile)
{
strname = FileUploadImage.FileName.ToString();
FileUploadImage.PostedFile.SaveAs(Server.MapPath("~/UserImage/") + strname);
} // <-- ADDED SO THAT WE JUST SAVE THE FILE IF THE FILE IS UPLOADED
// THEN UNCHANGED WE SAVE THE DATA TO THE DB
string str = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
string getADPOST = "Insert INTO USERPost (UserName,ContentPost,ImageName1) values (@UserName,@ContentPost,@ImageName1)";
// string getADPOST = "Insert INTO CommunityFollow (MyUserName,FriendUserName,CommunityStatus) values (@MyUserName,@FriendUserName,1)";
using (SqlConnection con = new SqlConnection(str))
{
using (SqlCommand cmd = new SqlCommand(getADPOST, con))
{
// Get Filename from fileupload control
// string filename = Path.GetFileName(FileUploadImage.PostedFile.FileName);
// Save images into Images folder
// Server.MapPath("~/UserImage/" + FileUploadImage.FileName);
// cmd.Parameters.AddWithValue("@ImageName1", filename);
// cmd.Parameters.AddWithValue("@ImageName1", "~/UserImage/" + filename);
cmd.Parameters.AddWithValue("@ContentPost", TextBixcomment.Text.Trim());
cmd.Parameters.AddWithValue("@UserName", username);
cmd.Parameters.AddWithValue("@ImageName1", strname);
//cmd.Parameters.AddWithValue("@VideoName", strname);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
// Response.Redirect("Home.aspx");
string message = "Post submitted successfully.";
string script = "window.onload = function(){ alert('";
script += message;
script += "')};";
Page.ClientScript.RegisterStartupScript(this.GetType(), "SuccessMessage", script, true);
}
}
}
// } ONE OF THIS DISAPPEARS AS WE CLOSED THE IF BLOCK MUCH EARLIER
}
this.GetData();
}
protected void linkbtn_Click(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal9t();", true);
}
protected void GetMergedAll_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "SharePost")
{
int index = Convert.ToInt32(e.CommandArgument);
DataTable dt = (DataTable)ViewState["DataTable"];
IEnumerable<DataRow> query = from i in dt.AsEnumerable()
where i.Field<int>("Id").Equals(index)
select i;
DataTable detailTable = query.CopyToDataTable();
SharePost.DataSource = detailTable;
SharePost.DataBind();
}
if (e.CommandName == "Details")
{
int index = Convert.ToInt32(e.CommandArgument);
DataTable dt = (DataTable)ViewState["DataTable"];
IEnumerable<DataRow> query = from b in dt.AsEnumerable()
where b.Field<int>("Id").Equals(index)
select b;
DataTable detailTable = query.CopyToDataTable();
GETVIDEO.DataSource = detailTable;
GETVIDEO.DataBind();
}
}