Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
How to grab a Cell value based on SelectedRows selection
posted

now i have a webdatagrid had two columns

and i selected some rows

but how can i grab the value of selected rows of column one

the code are below:

protected void BtnConfirm_Click(object sender, EventArgs e)
{
string ss = "";
SelectedRowCollection selectedRows = this.WebDataGrid1.Behaviors.Selection.SelectedRows;

if (selectedRows.Count > 0)
{
for (int i = 0;i<= selectedRows.Count - 1; i++)
{
if (selectedRows[i].Items[0].Value!=null)
ss = selectedRows[i].Items[0].Value.ToString();
}
}
}

  • 17590
    Offline posted

    Hello yake wang,

    Thank you for posting in the community.

    I know it`s been a while since you posted but if you are still in need of assistance I would be glad to help.

    I followed the steps that you suggested and I succeded in getting the values for the first column in the selected rows using the very same code as you do.


    protected void Button1_Click(object sender, EventArgs e)

        {

           string ss = "";

           

    SelectedRowCollection selectedRows = this.WebDataGrid1.Behaviors.Selection.SelectedRows;

           

    if (selectedRows.Count > 0)

            {

               for (int i = 0; i < selectedRows.Count; i++)

                {

                   if (selectedRows[i].Items[0].Value != null)

                        ss = selectedRows[i].Items[0].Value.ToString();

                }    

         }

     }

    I made a small sample project illustrating the scenario and I am attaching it for your reference. I am setting a breakpoint at the ss variable and the ss is correctly populated with the values of the cells in the first column.

    Please let me know if you have any additional questions regarding this matter.

     

    WDGSelectedRowsValues.zip