well i am new to Grid View , so i am taking a simple scenario. well i have a visual webpart
in sharepoint ; i have added a grid view with first column is of CheckBox Type
& it has a Button
& aLabel
i populate the grid view from an array of cities & i want that when button is clicked all the checked cities are appended in to the label. code is below.
protected void Page_Load(object sender, EventArgs e)
{
string[] States = new string []{ "Delhi", "Mumbai", "Pune", "Indaore" };
gvStates.DataSource = States;
gvStates.DataBind();
gvStates.Visible = true;
btnShow.Click += new EventHandler(btnShow_Click);
}
void btnShow_Click(object sender, EventArgs e)
{
// what should i write here to append checked value to label
// lblCites.Text +=
}
while working i found that when button is clicked the page_load function build the grid view again & there fore all check boxes are initialised .
please complete my code !!!!!
i do not want to do the same by using Javascript. i want to do this by C# only
& if possible please tell me the way how can i put a checkbox near "Show" button that is used to check all the check boxes.
thanks in advance!!
First, DO NOT bind the grid on each page load, but rather do that inside !Page.IsPostBack condition and then from grid event handlers. This is the recommended approach for the MS grid and thus you do not compromise performance.
Next, explore the tutorial posted by boruchsiper - it is definitely very useful.
Finally, if you prefer more declarative approach with SP2010 list or SQL binding and do not mind using third party grids, give the telerik grid SP2010 web part a spin. They have a demo site here, you may be interested.