Wednesday, August 18, 2010

How can I get column value from dataset in c# windows application code behind?

I have c# window application, I create GridView to get data from database, coding is like this:





DataSet countrydata = countryinfo.GetCountryInfo(this.getDbfil鈥?br>

if (countrydata != null)


{


this.gvCountry.DataSource = countrydata.Tables[0];


}





//gvCountry is the name of GridView Control











In GetCountryInfo function, I used SqlDataAdapter to get records from DataBase which is fine





For string data type, I only need to show data value which is worked fine, but there are some data is Bool (for example column1), I need to show it in checkbox, for example, if column1 is true, then checkbox is checked, how can I get value of cloumn1? I have tried countrydata.Tables[0].Columns[';column1';]鈥?but it doesn't work, I cannot use %26lt;%# DataBinder.Eval(Container.DataItem, ';column1';)%%26gt; becaus eit is windows application not web application, I need to do everythig in code behind





Thanks a lotHow can I get column value from dataset in c# windows application code behind?
You can do this in gvCountry_Rowdatabound or gvCountry_Itemdatabound event.





Inside the event do the following.


Find your checkbox control using FindControl method.


get the boolean value from your data source.


and set the value to checkbox.

No comments:

Post a Comment