How to make the FormView to Show every Item I select from the Gridview by clicking on select near any line?

Hi,

I want to make the FormView to Show details on a selection line from GridView with an option for editing details.

(When I press on select near any line - his whole details will show at the form view)

i just added GridView & FormView for same DataSource, but they dont speak with each other.

how to make it work?

Thanks, Gil.

0
b007
7/24/2008 8:36:38 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

15 Replies
512 Views

Similar Articles

[PageSpeed] 34

This article should help you out even though it uses a DetailsView as opposed to a FormView:

http://www.asp.net/learn/data-access/tutorial-10-vb.aspx


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
7/24/2008 7:12:29 PM

Hi,  

I judt ednted that link above,

but I can get into screen in Figure 10, which I need to sete the GridView's SelcetedValue Property,

How to go to this screen?

What to do?

Thanks, Gil.

 

0
b007
7/24/2008 9:49:37 PM

Is it done with a FormView or DetailsView?

Need help on this badly...

Can u send me a good like for ir?

(When selecting a row in GirdView his Details will show in the FormView/DetailsVIew) 

Thanks, Gil.

0
b007
7/24/2008 11:01:24 PM

Somebody?

0
b007
7/25/2008 9:01:07 AM

All you need to do is add a ControlParameter to the DataSourceControl feeding your FormView or DetailsView, and make sure you point it to your GridView and the Property attribute will be set to SelectedValue. Therefore, when the Page is posted back, the DataSourceControl will get the SelectedValue (ID) from your GridVIew and use that to bind your FormView or DetailsView.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
7/25/2008 11:58:04 AM

Hi,

Can u tell me what I should write exactly?

I have this:

Every line in the GridView have a RadioButton (SelectedValue - return the PrimaryKey of the selected row in the Table which I want to present its detail in the form view).

string selectedValue = Request.Form["MyRadioButton"];

FormView1.DataSourceID = ?????

So what should I wirte in the FormView1.DataSorceID?

or what else I need to add here?

Thanks, Gil.

0
b007
7/25/2008 12:30:42 PM

If you have a RadioButton in every row of the GridVIew and you want to display the FormView for that particular row once the RadioButton is pressed, then within the CheckedChanged event handler of your RadioButton, you can retrieve a reference to the current GridViewRow from which you can then use to extract your ID value. 

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
{
	RadioButton rad = sender as RadioButton;
	GridViewRow gvr = rad.NamingContainer as GridViewRow;
}

Use this info then to populate your FormView.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
7/25/2008 12:47:29 PM

Just added that,

and I'm getting error here:

GridViewRow gvr = rad.NamingContainer as GridViewRow;

saying: Object reference not set to an instance of an object.

What to do?

 

0
b007
7/25/2008 1:10:07 PM

I'd have to see the context in which your RadioButtons reside.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
7/25/2008 1:30:43 PM

I did this:

Aspx:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="index"

DataSourceID="SqlDataSource2" Width="492px">

<Columns>

<asp:TemplateField>

<ItemTemplate>

<input name="MyRadioButton" type="radio"

value='<%# Eval("index") %>' />

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField="msg_Name" HeaderText="Msg Name" SortExpression="msg_Name" />

<asp:BoundField DataField="Msg" HeaderText="Msg Detail" SortExpression="Msg" />

</Columns>

</asp:GridView>

that's it..

 

0
b007
7/25/2008 3:41:17 PM

You need to use a server-side CheckBox control and make sure to declaratively define the CheckedChanged handler within the control.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
7/25/2008 3:44:50 PM

Ok,

Howto make it?

 

0
b007
7/25/2008 3:51:40 PM

Something like this I guess: 

<asp:radiobutton id="RadioButton1" runat="server" checked='<%# Eval("index") %>' 
	oncheckedchanged="RadioButton1_CheckedChanged" />

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
7/25/2008 4:11:53 PM

Thank u all.

Got it myself.

Thanks agian.

 

0
b007
7/25/2008 5:38:20 PM

I already showed you earlier in this thread. It's not complete, but hopefully this will get you started.


Thanks, Ed

Microsoft MVP - ASP/ASP.NET

0
ecbruck
7/25/2008 5:39:56 PM
Reply: