Hi there,

I'm quite new to ASP.NET development so i don't know what's the best way to do this...
I want to list some data in several rows and have a column with a checkbox or radiobutton that allows the user to select a row; Then I should get a value like an ID from that selected row and after a button click send that info to another page (or same page) but changing the displayed data based on the choice made before. Is that possible w/ datagridview or datalist? I mean without postbacks...

Recommended Answers

All 8 Replies

Yes,it is possible. Even if post back is made then also it is possible.

How do I generate a column with that kind of controls and add it to the data to be displayed?

Little bit i get what you want to achieve,but please explain properly in detail,exactly what should happen.
This will help me.

I have an XML string and I bind it to DataGridView and it shows correctly the data in a table; I would like to have a column with some kind of control such as a radio button or whatever so that the user could select a row. Then I would pick, probably using JavaSrcipt, some value associated to that row and assync send it to the server-side, then I would present the user with a new interface based on the row selected before...
I hope i was clear; English is not my first language.. ;)

Thank you for your time.

:D :D ;)
Yes , it is crystal clear now.
1) Put a boundField into it.
2) Convert it into Template
3) Goto template editing mode and remove everything given inside the ItemTemplate,and put a radio button or Check box there.

4) To get the current selected row and values in that row,you must have fired the selected index changed event any how as per my knowledge.
----- Use Ajax update panel instead. -----

5) so again bound your grid view with select button or something,and apply some css to hide it,so that the normal select button is not visible.

6) Now in the row_databound event of your gridview write some code like this

protected void urgrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].Attributes["onmouseover"] = "if(this.style.backgroundColor!='silver'){this.style.backgroundColor='#E2E2E2';}this.style.cursor='hand';";
            e.Row.Cells[0].Attributes["onmouseout"] = "if(this.style.backgroundColor!='silver'){this.style.backgroundColor='white';}";
            e.Row.Cells[0].Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.urgrid, "Select$" + e.Row.RowIndex);
         }
}

7) the above given code will provide you to have a clickable row interface without having your select button to be clicked. When you click any row on first cell,it will fire your grid's selected index changed even and this is what we want so that we can get the selected row.
--I have considered that you have that clickable radio button or checkbox in your first column. Else change that Cells value.

8) Now in the selected index changed event,write whatever you wanted to achieve.

I hope it is clear :D

commented: Thanks +1

Good Mood :)
I'll try it out when I can, maybe in the next couple of hours. I'll let you know how it worked for me.
Thank's again for your time. Much appreciated.

Cheers

Hello Akash Saikia,

Came back to give you some feedback...
Well, I sorted it out thanks to some of your instructions. Thank you so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.