Alright so I have a gridview that I want to populate on Page Load with records specific to the user that has logged in. Currently the Gridview isn't populating because no UserID value is being passed to the gridview in order to return the record set. If
I set a static value in the HiddenField Value then the Gridview returns a recordset but I want it to be dynamic based on the User that logs in. I tried this
I get an input string error with this, when I put a breakpoint on the code, it shows that the dataset is returning null. I have set the gridview to access the hiddenfield value in order to populate the gridview, is there another way to access the ID from
the dataset so that I can have the gridview populated on Page Load based on the user accessing it.
you can set the value of this hidden field in Page_Load like below:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
UserID.Value=Session["yourUser"].ToString();
//your code further to bind the gridview
}
}
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Marked as answer by Qi Wu - MSFT on May 03, 2012 02:51 PM
I cannot see the DataSource anywhere, the ideal code should be :
UserGrid.DataSource=<yourDataTable or DataSetName>;
UserGrid.DataBind();
can you please tell us what is coming in your datasource?
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
rankone
Member
53 Points
53 Posts
HiddenField Value for GridView
Apr 25, 2012 12:25 AM|LINK
Hello Everyone!
Alright so I have a gridview that I want to populate on Page Load with records specific to the user that has logged in. Currently the Gridview isn't populating because no UserID value is being passed to the gridview in order to return the record set. If I set a static value in the HiddenField Value then the Gridview returns a recordset but I want it to be dynamic based on the User that logs in. I tried this
APSX Page:
C# (Page Load):
I get an input string error with this, when I put a breakpoint on the code, it shows that the dataset is returning null. I have set the gridview to access the hiddenfield value in order to populate the gridview, is there another way to access the ID from the dataset so that I can have the gridview populated on Page Load based on the user accessing it.
Any help is appreciated.
Thanks.
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: HiddenField Value for GridView
Apr 25, 2012 06:54 AM|LINK
you can set the value of this hidden field in Page_Load like below:
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { UserID.Value=Session["yourUser"].ToString(); //your code further to bind the gridview } }Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
rakeshreddym
Member
299 Points
79 Posts
Re: HiddenField Value for GridView
Apr 25, 2012 11:15 AM|LINK
Hi rankone ,
before assigning value to userid, your calling gridview with null value input so only it returns error.
onload you use
userid = sessionget("UserName")
pass this userid to gridview. i hope this will help you.
rankone
Member
53 Points
53 Posts
Re: HiddenField Value for GridView
Apr 25, 2012 01:48 PM|LINK
I tried this: ("11810" represents an UserID, I just tried to keep it static first to see if the gridview works)
if (!Page.IsPostBack) { UserID.Value = Session["11810"].ToString(); UserGrid.DataBind(); }I got a NullReferenceException message that an object isn't set to an instance. Is there a way I can set a dataset to the hiddenfield value?
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: HiddenField Value for GridView
Apr 25, 2012 05:36 PM|LINK
I cannot see the DataSource anywhere, the ideal code should be :
can you please tell us what is coming in your datasource?
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
sriramabi
Contributor
4351 Points
1277 Posts
Re: HiddenField Value for GridView
Apr 25, 2012 07:27 PM|LINK
Hai
remove Value=""
<asp:hiddenfield runat="server" ID="UserID" />
http://forums.asp.net/t/1221545.aspx/1/10
thank u