Click here to Skip to main content
15,909,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

Plz tell how to find a specific value from view state,

i have 3 cloumns in viewstate,sNO, Name, Contact respectively.

i want to find sNo for comparing in IF() condition ,


Please Answers,,
Posted
Comments
Zafar Sultan 7-Oct-13 3:28am    
How are you storing the values in viewstate?
xibit89 7-Oct-13 3:34am    
CheckBox cBox2 = null;
for (int i = 0; i < lvItemTone2.Items.Count(); i++)
{
cBox2 = (CheckBox)lvItemTone2.Items[i].FindControl("lvTone2chckSelect");
if (cBox2.Checked)
{
ItemCode = ((DropDownList)GridView1.FooterRow.FindControl("ddlItemCode")).SelectedItem.Text.ToString();
BatchNo = ((Label)lvItemTone2.Items[i].FindControl("lblBatchNo")).Text;
Quantity = ((Label)lvItemTone2.Items[i].FindControl("lblQty")).Text;
SelectedQuantity = ((Label)lvItemTone2.Items[i].FindControl("lblSelQty")).Text;

dr = dt.NewRow();
dr["BatchNo"] = BatchNo;
dr["Quantity"] = Quantity;
dr["SelectedQuantity"] = SelectedQuantity;

if (dr != null)
{
dt.Rows.Add(dr);
}
}
}
ViewState["BatchTable"] = dt;
lvItemTone2.DataSource = dt;
lvItemTone2.DataBind();
Azee 7-Oct-13 4:21am    
Hey there, I don't see sNO, Name or Contact being saved in the ViewState, there is BatchNo, Quantity and SelectedQuantity.
xibit89 7-Oct-13 4:28am    
yep sNO, Name, Contact i used for explaning.. above is the actual code

Hey there,

Let's suppose you want to get BatchNo from the DataTable that you stored in the ViewState:
C#
if(ViewState["BatchTable"] != null)
{
    DataTable dt= (DataTable)ViewState["BatchTable"];
 
    for(int i = 0; i < dt.Rows.Count; i++)
    {
        string batchNo = dt.Rows[i]["BatchNo"].ToString();
        if(batchNo.Equals("Your Value to Compare"))
        {
            //Do Something
        }
    }
}


Hope this helps, let me know if this isn't what you were looking for.

Azee...
 
Share this answer
 
First you have convert your viewstate to a specific type like datatable, List<clasobject>
Then you can filter it.
Ex.
DataTable myDt=(DataTable)ViewState["viewstatename"];

From myDt you can filter your datab by the if condition
See I have not given any code it's a format to understand the concept
 
Share this answer
 
first of All you have to convert this viewstate into datatable
For Example

datattable abc=(datatable)viewstate("temp");
after this

you will type abc.Rows[0]["sNO"].tostring()

try this
 
Share this answer
 
Since you are storing the data as a datatable you will have to retrieve it in the same way:

C#
DataTable YourDataTable = (DataTable)ViewState["BatchTable"];

string BatchNo = "";
string Quantity = "";
string SelectedQuantity = "";

for(int i = 0; i < YourDataTable.Rows.Count; i++)
{
BatchNo = YourDataTable[i]["BatchNo"].ToString();
Quantity = YourDataTable[i]["Quantity"].ToString();
SelectedQuantity = YourDataTable[i]["SelectedQuantity"].ToString();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900