how can show data in textbox select the datalist

Posted by Neha-kapoor under ASP.NET on 6/30/2011 | Points: 10 | Views : 3465 | Status : [Member] | Replies : 6
Dear All pls check this code and tell where the error
i m populate datalist and when click the user on datalist row
then show the selected item on textbox
pls check this

protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Edit")
{

Label id = (Label)e.Item.FindControl("lnk");
Label c_type = (Label)e.Item.FindControl("cat");
TextBox1.Text = id.Text;
TextBox2.Text = c_type.Text;
}
}



And this the shource code
<body>
<form id="form1" runat="server">
<div>

<asp:DataList ID="DataList1" runat="server" DataKeyField="ID"
DataSourceID="AccessDataSource1">
<ItemTemplate>


<asp:LinkButton ID ="lnk" runat ="server" CommandName="edit" Text='<%# Eval("ID") %>' />

<asp:Label ID="cat" runat="server" Text='<%# Eval("cat_type") %>' />
<br />
<br />
</ItemTemplate>
</asp:DataList>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/blog.mdb" SelectCommand="SELECT * FROM [content]">
</asp:AccessDataSource>

<br />

</div>
</form>
</body>


thanks


Responses

Posted by: Lakn2 on: 6/30/2011 [Member] Starter | Points: 25

Up
0
Down
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "Edit")
{

LinkButton id = (LinkButton)e.Item.FindControl("lnk");
Label c_type = (Label)e.Item.FindControl("cat");
TextBox1.Text = id.Text;
TextBox2.Text = c_type.Text;
}
}




Thanks&Regards
LakshmiNarayana Nalluri.

Neha-kapoor, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neha-kapoor on: 6/30/2011 [Member] Starter | Points: 25

Up
0
Down
dear sir
i m trying this but not show any record
i send my sample code pls check this
plss help me sir
 Download source file

thanks

Neha-kapoor, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/30/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
Modified your code and attached. Please take a look at it.
Changes made
1. Event was not registered that's why it it was not triggered.
2. CommandName was "edit " in ASPX file and in Code behind file you are comparing with "Edit ".

Thanks,
Debata

 Download source file

Neha-kapoor, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neha-kapoor on: 6/30/2011 [Member] Starter | Points: 25

Up
0
Down
thanks sir
dear sir if i want to show the data on next page
like
if user click the asp.net link then redirect the page next page and show ID and Cat_type
in a lable,how can i do this can you help me plssssssssssssssssssssssssssssssss
pls edit attachment

thanks

Neha-kapoor, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/30/2011 [Member] Starter | Points: 25

Up
0
Down
There are many ways how to pass data from one page to other.
In that sample, I have tried just two ways.( Query string and Session).
http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
http://www.asp.net/general/videos/how-do-i-pass-information-from-one-page-to-another-using-a-query-string

On passing data using query string , in some case you need to url encode the data , as it may contain some invalid character like # in c#.
upon receiving you have to url decode the query string.
http://shawpnendu.blogspot.com/2009/04/passing-dataparametersvalues-from-one.html

Thanks,
Narayan
 Download source file

Neha-kapoor, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Neha-kapoor on: 7/1/2011 [Member] Starter | Points: 25

Up
0
Down
Narayan ji
thanks for your reply and giving time to us
so kind person

thanks

Neha-kapoor, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response