how to load groups in listView using Facebook SDK C# - c#

I am using Facebook SDK c# to make windows application.
I try to load all page which I like it is successful.
The problem is when I press the load page button it load this data 1 more to become have duplicate, and get every page I like it 2 times
my code
private void button2_Click(object sender, EventArgs e)
{
string[,] friends;
FacebookClient fb = new FacebookClient(AppSettings.Default.AccessToken);
dynamic Grouplist = fb.Get("/me/likes");
int count = (int)Grouplist.data.Count;
friends = new string[count, 1];
for (int i = 0; i < count; i++)
{
listView3.Items.Add(Grouplist.data[i].name);
}
}

listView3.Items.Clear();
for (int i = 0; i < count; i++)
{
listView3.Items.Add(Grouplist.data[i].name);
}

Related

c# comboBox updated by array in a method

I am fairly new to C#.
I trying to create a Combo Box that displays numbers from 1-100 generated from the method below. I am using an example that found on the internet and modifying it to meet my needs.
I can't get my combo box to display anything. Please offer suggestions or a better way to execute my intended goal.
private void Range()
{
ArrayList arr = new ArrayList();
for (int i = 0; i <= 100; i++)
{
arr.Add(i);
}
}
public void FillInComboBox(ComboBox target, int start, int end)
{
for(int i = start; i <= end; i++)
{
target.Items.Add(i);
}
}
Usage
private void Form2_Load(object sender, EventArgs e)
{
FillInComboBox(comboBox1, 0, 100);
}

ASP.NET Storing data to container class

The problem is that when I read data from txt file with button_1 I place it in container class. When I want to print container data with button_2 in web site -container becoming empty. So the question is how to store data into container class?
Container:
public class Matrix
{
public int[,] matrix;
public Matrix()
{
matrix = new int[6, 6];
}
public void AddNumber(int numb, int i, int j)
{
matrix[i, j] = numb;
}
}
Web form:
public partial class Forma : System.Web.UI.Page
{
Matrix m = new Matrix();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void UploadButton_Click(object sender, EventArgs e)
{
}
protected void Start_Button(object sender, EventArgs e)
{
char[] separators = {' ', '\n', '\r', '\t'};
int numb = 0;
int Counter = 0;
if (!FileUpload1.HasFile)
{
Label1.Text = "Nepasirinkote failo!";
}
else
{
Label1.Text = string.Empty;
StreamReader reader = new StreamReader(FileUpload1.FileContent);
string text = reader.ReadToEnd();
string[] allNumbers = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
{
numb = int.Parse(allNumbers[Counter]);
Counter++;
m.AddNumber(numb, i, j);
}
}
Label1.Text = m.matrix[0, 5].ToString();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Text = m.matrix[0, 5].ToString(); //Container infroamtion dissapears
}
}
As opposed to a SmartClient application, a web application creates a new instance of your page class for each request. So the code
Matrix m = new Matrix();
is called whenever you call the page or a postback occurs. So there is a new instance of the matrix and the previous one is gone the moment the first request ends.
There are some methods to store data between requests, each with their ups and downs:
You can store the data in ViewState. Be aware that the ViewState is transferred to the client and sent back to the server, so you only want to do this with small amounts of data.
You can store the data in Session cache. This can reduce the amount of users your application can handle per server because for each user the memory is allocated. Also, if you have a multi-server environment (Web farm), you need to make sure that each server can access the Session cache because a new request can usually be handled by a different server.
The common pattern that is used with database data is to re-read data for the new request. As you get the file by upload, you could store the data in a database when receiving the file and re-read from the database. You'd need to make sure that you purge the data in the database in case it is not needed permanently.
This link provides an overview of the various state management methods that are available in ASP.NET WebForms. Be aware that some of them are user-specific whereas others are shared by all users.

.net - How to add controls dynamically?

I want to add dynamic controls
Like the below image I want to do
I am struggling to do that
If I click Add More Experience button I want to display another rows
I tried with user control but it is not working properly.
Below code is working fine but if I add controls then close the browser page and then open the browser again added controls are coming.
I think the problem is static int i=0;
static int i = 0;
protected void addnewtext_Click(object sender, EventArgs e)
{
i++;
for (int j = 0; j <= i; j++)
{
AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
placeHolder.Controls.Add(ac);
placeHolder.Controls.Add(new LiteralControl("<BR>"));
}
}
Please provide your ideas? Thanks in advance
As per my comment, when using a static variable within an ASP.Net page, it will be shared amongst all users until the application pool or server is restarted.
Instead you should really be using a ViewState or similar to read/write the value.
private int controlCount
{
get
{
int val = 0;
try
{
val = (int)Page.ViewState["ControlCount"];
}
catch(Exception e)
{
// handle exception, if required.
}
return val;
}
set { Page.ViewState["ControlCount"] = value; }
}
protected void addnewtext_Click(object sender, EventArgs e)
{
int i = controlCount++;
for (int j = 0; j <= i; j++)
{
AddVisaControl ac = (AddVisaControl)Page.LoadControl("AddVisaControl.ascx");
placeHolder.Controls.Add(ac);
placeHolder.Controls.Add(new LiteralControl("<BR>"));
}
}

Visual C# 2008 : Non-invocable member 'Microsoft.VisualBasic.Devices.Ports.SerialPortNames' cannot be used like a method

can someone help me with this problem..? got this error when try debugging the code..
private void Form2_Load(object sender, System.EventArgs e)
{
this.Show();
Form1.DefaultInstance.Close();
ToolTip1.SetToolTip(ComboBox1, "Please enter a VALID phone number");
ToolTip1.SetToolTip(ComboBox2, "Please check your COM port number before selecting. Connection could be made for outgoing cable or bluetooth port with data calling supported phone.");
ComboBox1.SelectedIndex = 0;
for (int i = 0; i < My.Computer.Ports.SerialPortNames.Count; i++)
{
ComboBox2.Items.Add(My.Computer.Ports.SerialPortNames(i));
}
ComboBox2.SelectedIndex = 0;
}
this happen at "SerialPortNames" in this line :
ComboBox2.Items.Add(My.Computer.Ports.SerialPortNames(i));
You probably want to use indexer - [] instead of method call ()
for (int i = 0; i < My.Computer.Ports.SerialPortNames.Count; i++)
{
ComboBox2.Items.Add(My.Computer.Ports.SerialPortNames[i]);
}
Perhaps try
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox1.Items.Add(sp)
Next
This was taken from http://msdn.microsoft.com/en-us/library/yfbcbt43(v=vs.90).aspx
You're using it like a method rather than a collection (following it with (i)).
Try one of these two:
for (int i = 0; i < My.Computer.Ports.SerialPortNames.Count; i++)
{
ComboBox2.Items.Add(My.Computer.Ports.SerialPortNames[i]);
}
or
foreach(var portname in My.Computer.Ports.SerialPortNames)
{
ComboBox2.Items.Add(portname);
}

Access the data in Gridview in runtime when it set auto generate?

i imported my data from Excel sheet to grid view.after that i want to put the column header text of my grid view into drop down,but i can't access them
help me plz :-( ;
this is my code but it dose not work :
List<string> lst = new List<string>();
* for (int i = 0; i < dg_excel.Columns.Count; i++)
{
lst.Add(dg_excel.Columns[i].HeaderText);
}
ddl_prd_count.DataSource;
ddl_prd_count.DataBind();
for this * line it says to me there are no columns (column.count = 0)
Check answer on another SO thread Why column count is 0 for GridView to know that why are you not able to access the columns from your grid's Columns collection.
In my opinion, if you want to use auto generated columns then follow this ASP.net forum link - Customizing Auto Generated Columns (GridView) and SO thread How to hide columns in an ASP.NET GridView with auto-generated columns?.
e.g.
have an idea from this code.. i have not checked the proper syntax etc in it.
protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
if (IsFillCombo)
{
//fill your list here.
for (int i = 0; i < datasourcetable.Columns.Count; i++)
{
lst.Add(e.Row.Cells[i].Text);
}
IsFillCombo = false;
}
}
}
// Another simplest way to implement this as below: From Question Text
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<Abc> listofAbc = new List<Abc>();
for (int i = 0; i < 10; i++)
{
listofAbc.Add(new Abc
{
ID = i + 1,
Name = "Abc" + (i + 1).ToString()
});
}
GridView1.DataSource = listofAbc;
GridView1.DataBind();
List<string> lst = new List<string>();
for (int i = 0; i < GridView1.HeaderRow.Cells.Count; i++)
{
lst.Add(GridView1.HeaderRow.Cells[i].Text);
System.Diagnostics.Debug.WriteLine(GridView1.HeaderRow.Cells[i].Text);
}
}
}
}
public class Abc
{
public int ID { get; set; }
public string Name { get; set; }
}
you can use following code
List<string> lst = new List<string>();
for (int i = 0; i < dg_excel.HeaderRow.Cells.Count; i++)
{
lst.Add(dg_excel.HeaderRow.Cells[i].Text);
}
ddl_prd_count.DataSource=lst ;
ddl_prd_count.DataBind();
Access gridView1_CellValueChanged event of your grid
and then accesse.Column.FieldName.ToString()

Categories

Resources