Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 25, 2012 07:27 PM by sriramabi
Apr 25, 2012 12:25 AM|LINK
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
<asp:hiddenfield runat="server" ID="UserID" Value="" />
C# (Page Load):
Dataset dsUserID = UserName.SProd.GetUserID(Convert.ToInt32(UserID.Value))
UserID.Value = dsUserID.Tables.Rows["UserID"].ToString();
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.
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)
//your code further to bind the 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.
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)
UserID.Value = Session["11810"].ToString();
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?
Apr 25, 2012 05:36 PM|LINK
I cannot see the DataSource anywhere, the ideal code should be :
UserGrid.DataSource=<yourDataTable or DataSetName>;
can you please tell us what is coming in your datasource?
Apr 25, 2012 07:27 PM|LINK