开发者

Log Selection of DropDownList in Text File

I am trying to log the selection a user makes when they select a choice from a dropdownlist. I have autopostback enabled and when a user selects a choice it updates content on the page. I also have a search button for people who like to click search. I know I need to use the SelectedIndexChanged

 protected void CategoryDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
        TextWriter sw = new StreamWriter("selectordata/results.txt");
        sw.WriteLine(//Write Data Here);
        sw.Close();
        }

My first question is how do I write what Selection they just made in the SelectedIndexChanged. I cant call CategoryDropDownList.SelectedValue can I?

Secondly Is there any way I can keep track of if it is the same user. Mean Idealy in my text file I would like to store it like this

8/12/2011 10:56 AM SESSIONID(or something) Selected Category #1

8/12/2011 10:57 A开发者_如何学CM SAME SESSIONID Selected Product #2

Can this be done easily?


If you know the selected index, you can retrieve the item from the collection or just the selected value:

 string value = myDropDownList.SelectedValue;
 ListItem item = myDropDownList.Items[myDropDownList.SelectedIndex];

If you need to find the specific user's session Id, you can grab that from your session object (assuming you are using Microsoft's default Session):

HttpContext.Current.Session.SessionID


you can call DropDownList.SelectedValue and you can also store your userId is some sort of session and retrieve using Session["key"].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜